cancel
Showing results for 
Search instead for 
Did you mean: 

Create a file path with a date in File Writer snap

SnapWizard
New Contributor III

I have a pipeline that generates an output file that I would like to save in S3 with a file path of
YYYY/MM/dd/file_name… e.g. S3://bucket/2023/08/09/file_name.csv. When I do this:
“s3:///bucket/”+Date.now().getFullYear()+“/”+Date.now().getMonth()+“/”+Date.now().getDate()+“/fil_name.csv”
It generates a path of 2023/8/9, How can I programmatically determine when to pad it with a ‘0’ for single digit months and days without including this data in the document being saved?

2 REPLIES 2

koryknick
Employee
Employee

Personally I like pipe.startTime over Date.now() since it is consistent throughout your pipeline execution and correlates to your pipeline execution time in the Dashboard - try this:
"s3:///bucket/" + pipe.startTime.toLocaleDateString( { format : "yyyy/MM/dd" } ) + "/filename.csv"
This should yield what you’re looking for.

SnapWizard
New Contributor III

I placed the logic in the csv formatter and stored it as a variable and used the variable as part of the path used by the writer snap. This worked.
image