Solved

Date in Filename Parameter

  • 21 October 2019
  • 6 replies
  • 112 views

Badge +7

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?

icon

Best answer by takashi 21 October 2019, 17:13

View original

6 replies

Userlevel 2
Badge +17

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')
Badge +7

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.

Badge +7

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.

Userlevel 2
Badge +17

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.

Badge +7

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!

Badge +5

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

Reply