Solved

How do I create a folder whose name is based on the date the Workbench is run?


Hi all,

Just taking my first steps with FME. I am using the FTPCaller to download two .zip files that are provided on a weekly basis. When I specify an existing folder everything works fine. However, I'd actually like to download the .zips to a folder whose name is actually the date on which the download took place. However, when I try and incorporate this into the FTPCaller's 'Target File' path (e.g. C:\\Downloads\\@DateTimeFormat(@DateTimeNow(),%Y_%m_%d)\\@filename) the translation fails as the file is unable to be written.

If the FTPCaller is unable to create a destination folder on the fly, how would I go about creating the folder?

Any suggestions appreciated!

Thanks!!

icon

Best answer by fmelizard 4 March 2018, 08:06

View original

13 replies

Badge +22

You can use either the SystemCaller, or a PythonCaller to make the directory prior to the FTPCaller.

Badge +6

Because there is no such funciton as @filename in FME?so an error occurs.

C:\\Downloads\\@DateTimeFormat(@DateTimeNow(),%Y_%m_%d)\\@filename

Userlevel 4
Badge +13

The FTPCaller should make the directory for you, so that is a bug on our side which we'll get to.

In the meantime, @jdh is right, Python is the way to go. Turns out @takashi has shown us how a while ago, so I put together a sample that should help you get going: testdirectorymaker.fmw

You can use either the SystemCaller, or a PythonCaller to make the directory prior to the FTPCaller.

Many thanks JDH. I initially used the system caller to create the folders, but have switched to the python caller so that I can create the folders and unzip the downloads at the same time.

 

 

Thanks again!

 

 

The FTPCaller should make the directory for you, so that is a bug on our side which we'll get to.

In the meantime, @jdh is right, Python is the way to go. Turns out @takashi has shown us how a while ago, so I put together a sample that should help you get going: testdirectorymaker.fmw

Thanks Dale - the Python caller worked a treat.

 

Because there is no such funciton as @filename in FME?so an error occurs.

C:\\Downloads\\@DateTimeFormat(@DateTimeNow(),%Y_%m_%d)\\@filename

Hi taojunabc - sorry this was a typo on my part. It should have been ...\\@value(filename). I resolved the issue using Python caller. Thanks for your help.

 

 

Userlevel 4
Badge +13

Took a bit longer than we hoped, but for the record, this is fixed as of FME 2019.2 build 19790 and will be in FME 2020 betas with builds later than 20110.

Badge +1

The FTPCaller should make the directory for you, so that is a bug on our side which we'll get to.

In the meantime, @jdh is right, Python is the way to go. Turns out @takashi has shown us how a while ago, so I put together a sample that should help you get going: testdirectorymaker.fmw

Thank you Dale, this worked well. I just have a follow up question. If you set the folders with the Python Caller, how can you set the Dataset Source Folder and File pathname of new Writers? Say you would like to export your fme data to an Excel Writer that you would like to add to your newly created Folder?

I have attempted to use Feature merger and been messing around with the Dynamic Schema, but cant seem to get it working.

 

Thanks in advance

The FTPCaller should make the directory for you, so that is a bug on our side which we'll get to.

In the meantime, @jdh is right, Python is the way to go. Turns out @takashi has shown us how a while ago, so I put together a sample that should help you get going: testdirectorymaker.fmw

@Dale Lutz​ I wonder if it has been to long to ask if you could repost the workspace? This is a python caller sample that would greatly help me.

Userlevel 4
Badge +13

Looks like my attachment got dropped from the previous answer, but I've re-uploaded it below.

Userlevel 4
Badge +13

@Dale Lutz​ I wonder if it has been to long to ask if you could repost the workspace? This is a python caller sample that would greatly help me.

Yes, it looks like it was lost -- see attached.

Userlevel 4
Badge +13

Thank you Dale, this worked well. I just have a follow up question. If you set the folders with the Python Caller, how can you set the Dataset Source Folder and File pathname of new Writers? Say you would like to export your fme data to an Excel Writer that you would like to add to your newly created Folder?

I have attempted to use Feature merger and been messing around with the Dynamic Schema, but cant seem to get it working.

 

Thanks in advance

Sorry for not noticing this before -- the way to proceed would be to use a FeatureWriter after the PythonCaller. But depending on exactly what you want to do, things are either a bit more complex, or simple, depending on your point of view.

 

For one thing, the Excel writer will create the directory for you -- so there is no need to use the PythonCaller. If you give the Excel writer "C:\\Path\\To\\My\\File.xlsx" -- it will make all those directories if they don't already exist. So there is no need to make use of the python in this case.

 

If this is still causing you trouble, please post a fresh new question with details of your scenario (esp what the input is) and the voices of the FME community will chime in. Pretty sure we can solve this, just a matter of knowing the details....

Badge +11

I've been doing this to create new "directories" for downloading sftp files

FTPCaller_Creating New Directory_working

Reply