Question

Python shutdown script

  • 13 November 2012
  • 3 replies
  • 22 views

I am using FME to produce a number of .xls files and need to rename those files by adding the current date (and time hopefully) to the file name at the end of the process using a shutdown python script. I have cobbled below together from information I have found online but it won't work and I don't have python knowledge to fix it.

 

 

import os, datetime path='C:\\FME' to_ext='*.xls' for file_name in os.listdir(path):             root, ext = os.path.splitext(file_name)             t = os.path.getmtime(file_name)             v = datetime.datetime.fromtimestamp(t)             x = v.strftime( ' %d-%m-%Y')                   os.rename(os.path.join(path, file_name), os.path.join(path, root+x+to_ext))

 

 

 

I would appreciate any help.

 

 

Thanks

3 replies

Userlevel 4
Badge +26
Not sure about the Python, but I would use the TimeStamper to find the current date/time, generate the output file name with the AttributeCreator, then use a fanout on that name to create the output.

 

 

For a non-Python use, I think that would be easier.

 

 

Regards

 

 

Mark

 

 

Mark Ireland | Product Evangelist

 

Safe Software Inc.

 

Suite 2017, 7445-132nd Street, Surrey, BC, CANADA

 

T 604.501.9985 | F 604.501.9965

 

| Twitter @FMEEvangelist | http://www.FMEevangelist.com

 

Hi Mark

 

 

Thanks for your reply. I am not sure how to implement it though. I am reading the attributes of a single shapefile then applying an attribute filter to filter the data into 3 categories. Each of those are then written to a seperate excel file. Its the name of the excel files I want to change to allow the process to be run multiple times and preserve the output each time. 

 

 

I have tried adding a timestamper and attributecreator (to create a filename based on a concatenation of constant value and the timestamp) after the attributefilter but before the XLS_ADO file writer. It adds that value (the created filename) to every row of the output. I am not sure this is right and don't know how use that for the .xls file name?

 

 

Regards

 

 

Badge
Following on from Mark's answer, and explaining how you rename each XLS file with the attribute you have created. You need to use the "Fanout Dataset" (search for this in help) which is an advanced parameter. Set the fanout directory to where you want the data to go and use the attribute you created as the "Attribute to Fanout on" (Just make sure to the attribute would be valid as a filename i.e. no illegal characters).

 

 

Good luck

 

 

Todd

Reply