Skip to main content
Solved

Date in Filename Parameter

  • October 21, 2019
  • 6 replies
  • 636 views

pflegpet
Contributor
Forum|alt.badge.img+8

Hi,

I have a workspace that downloads two different files (1 geopackage, 1 textfile), renames them and stores them in a ZIP file. Said ZIP should contain the current date in its filename. Normally I use the date/time functions in the filepath paramters to create the current date on the fly but the options in "Destination Fanout Directory" do not offer these functions. As a workaround a created a Text Parameter where the user enters the current date manually but if possible I would like to do this automatically. Can this be done somehow?

Best answer by takashi

Another thought. If you add an attribute which stores the current date with an appropriate format to every feature in the workflow, you can set the destination zip filename containing the date string and the archived filename as Fanout Expression in the writer. e.g.

View original
Did this help you find an answer to your question?

6 replies

takashi
Contributor
Forum|alt.badge.img+19
  • Contributor
  • October 21, 2019

Hi @kasparlov, a possible workaround is to define a scripted parameter that returns the current date. See here to learn more about scripted parameter: Type: Scripted (Python) and Scripted (Tcl)

Scripted (Python) Parameter Definition Example:

from datetime import date
return date.today().strftime('%Y_%m_%d')

pflegpet
Contributor
Forum|alt.badge.img+8
  • Author
  • Contributor
  • October 21, 2019

Hi @takashi,

I assumed that a scripted parameter could work but I'm too much of a beginner in Python to get the desired result. Thanks anyways, I try to work from your linked example.


pflegpet
Contributor
Forum|alt.badge.img+8
  • Author
  • Contributor
  • October 21, 2019
pflegpet wrote:

Hi @takashi,

I assumed that a scripted parameter could work but I'm too much of a beginner in Python to get the desired result. Thanks anyways, I try to work from your linked example.

I managed to create the scripted parameter using the second example from this tutorial.


takashi
Contributor
Forum|alt.badge.img+19
  • Contributor
  • Best Answer
  • October 21, 2019

Another thought. If you add an attribute which stores the current date with an appropriate format to every feature in the workflow, you can set the destination zip filename containing the date string and the archived filename as Fanout Expression in the writer. e.g.


pflegpet
Contributor
Forum|alt.badge.img+8
  • Author
  • Contributor
  • October 21, 2019
takashi wrote:

Another thought. If you add an attribute which stores the current date with an appropriate format to every feature in the workflow, you can set the destination zip filename containing the date string and the archived filename as Fanout Expression in the writer. e.g.

Neat! With this setup I can use my old approach with the "DateTime" function again. Thanks a lot!


tim_bkr
Participant
Forum|alt.badge.img+5
  • Participant
  • August 4, 2021
takashi wrote:

Another thought. If you add an attribute which stores the current date with an appropriate format to every feature in the workflow, you can set the destination zip filename containing the date string and the archived filename as Fanout Expression in the writer. e.g.

This is very useful ! To me, it should be integrated in the following article

https://community.safe.com/s/article/including-dates-into-the-names-of-output-files-or


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings