OL Learn

Using file name as a variable in the design template

Hi - this may be too far fetched and probably out of my league here but is there a way to get part of the data file name ( in this case a csv ) in the datamapper and use it as a variable in the template. For example - I have a csv file name 142812.T.000999081.DEES.119784297972154_20191213081518.csv. I need to use the last 14 digits and convert that into a date field as such - Friday, December 13, 2019 08:15:18 AM EST


In the Datamapper pre-processor, you have a Fixed automation properties named OriginalFilename. That gives you access to your original file name.

Then using javascript, extract the time stamp from it and convert it to date format. There is some manipulation of the string but you’ll manage :wink:

Hi - I am still trying to work through this. I have this working but still working on output format. Is there a way to extract the date from the file name when it is not in a static position. For example one file name will be 142812.T.000999081.DEES.119784297972154_20191213081518.csv.

I need to extract the date which will always be the last 14 digits. But the last name ( DEES ) will vary in length. I realized after I created the following script. Still trying to manipulate so my output looks like
Friday, December 13, 2019 08:15:18.
Option Explicit
Dim myFile, newFileName1, newFileName2, newFileName3

myFile = Watch.ExpandString("%O")
newFileName1 = mid(myFile,46,2)
newFileName2 = mid(myFile,49,2)
newFileName3 = mid(myFile,42,4)
Watch.SetVariable “ReqDate”, newFileName1 & “/” & newFileName2 & “/” & newFileName3


BTW, you could have done all this from within the Datamapper, no need of doing this in Workflow with VBScript.

Have you tried using REGEX?

I tried it with this: \d+.\w+.\d+.(\w+).\d+_\d+.\w+\g and it worked with the filename sample you posted. it returned DEES. Of course, this is if your filename has a fixed format, not in length but in what type of character we get, digits or alphabetical.

Thank you - I wasn’t exactly sure how to get it working in the Datamapper. I have done something similar like this in workflow, that’s why I used workflow.

Unfortunately I do not know REGEX. So, I haven’t tried it. I will try to get what you gave me above working though. Is there ant links that would help with REGEX. Always willing to learn something new!

Thank You


but I prefer this one: https://www.regular-expressions.info/tutorial.html

1 Like