Create variable from partial file name to pass to external program

Hi there

As the title suggests I need to create a variable from 2 parts of a file name to pass to an external program.

The input filename format (from folder capture) would be something like: 123456_xxxx_xxxx_xxxx-ABC001.ps

I need a variable created “on the fly” in workflow which would contain only the first and last parts separated by a space (excluding the extension) so the variable would look like: 123456 ABC001

I then want to use this variable to pass to an external program

Is this possible? If so, how could it be done?

I’m a novice so any help would be greatly appreciated.

Hi Marrd,

In a Run Script plugin add the following VBScript code. In your process, right click the process name and select Insert->Local Variable. Rename the variable to newFileName. The below script takes the first 6 characters of your input file name (stored in myFile, %O is original filename without extension) and stores it into a variable called newFileName1, then the last six characters stored into newFileName2. At the end I set the local variable mentioned before by concatenating the two variables separated by a space.

Option Explicit
Dim myFile, newFileName1, newFileName2

myFile = Watch.ExpandString("%O")
newFileName1 = Mid(myFile,1,6)
newFileName2 = Mid(myFile,23,6)
Watch.SetVariable "newFileName", newFileName1 & " " & newFileName2

Regards,
S

Since I can’t stop myself from attempting to convert everyone to Regular Expressions ( :stuck_out_tongue: ), here’s what a JavaScript version would look like:

var jobFile = Watch.GetOriginalFileName();
Watch.SetVariable("myVariable", jobFile.replace(/([^_]*)[^-]*-([^\.]*)(.*)/gi,"$1 $2"));

This is perfect. Thank you.