USE CASE:
I want to be able to generate output/report files from the dataflow based on the rundate / dateRanges and include these dynamic dates in the output filename itself.
SOLUTION 1: No coding required
The PathSafe variants of the built-in Run properties cater for the situation where an output file needs to include the date/ datetime the data flow was run. Specifically, the {{^RunDate_PathSafe^}} Run property substitution will result in a date string of the form YYYYMMDD.
The Help documentation is here: Help
You could include the Run property substitution in the output filename property of the publishing node, e.g. for an Analyze Server install:
Which would result in the following filename:
The Run property reference can be inserted from the context menu of the node property:
SOLUTION 2:
Alternatively, you can write out the file with a different name. To do that, connect a Transform node to the output file node, and add the Python code below which uses the rename function to rename the file.
In the Transform node, add this code:
Import os
out1 += in1
### setup new and old names
oldname=in1.FileName
now=datetime.datetime.now()
ddd=now.strftime("%Y%m%d")
newname=in1.filename.replace("_TEMP_",ddd)
out1.newf_ilename = newnameos.rename(oldname,newname)
The above examples are simply a suggestion, you may need to add additional code for more complex renaming, and to catch errors if the new file already exists.
Comments
0 comments
Please sign in to leave a comment.