Please note that VisualCron support is not actively monitoring this community forum. Please use our contact page for contacting the VisualCron support directly.


Kevin T
2016-09-02T00:05:40Z
I'm trying to copy files into a directory and changing the file names when it copies, the sources are like this:

PSZLEDSTB3001 rev 1 Instruction 2P FL.PDF
PSZLEDSTB2041 Instruction 4P FS.pdf
CAZLEDHDL1364 Instruction 1P FX.pdf

Where I need to replace from " Instruction*.pdf or PDF" to " Instruction Manual.pdf" then replace all the "spaces" to underscores. So the end result for the list above would be like:
PSZLEDSTB3001_rev_1_Instruction_Manual.pdf
PSZLEDSTB2041_Instruction_Manual.pdf
CAZLEDHDL1364_Instruction_Manual.pdf

Using wildcards in the replace string doesn't work. Can someone give me some help?
Sponsor
Forum information
Support
2016-09-02T12:24:02Z
I think, for that advanced logic you need to use RegEx. I suggest trying out one of many RegEx forums for a regex string you can use.
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
thomas
2016-09-02T14:56:36Z
If you don't fancy regex, then something like this should work (paste into variables, and you will see)

{STRING(Replace,{STRING(Substring|PSZLEDSTB3001 rev 1 Instruction 2P FL.PDF|0|{STRING(IndexOf|PSZLEDSTB3001 rev 1 Instruction 2P FL.PDF|Instruction)})}, ,_)}Instruction_Manual.pdf

Basically it does this:

1) Find position of the word 'Instruction'

2)Select the substring from start up to the index of 1)

3)Replace all spaces with _

4) Add the last static part of the filename, ie add this => Instruction_Manual.pdf

You have to add some error checking. Eg. if the word Instruction does not exist, it fails.
Kevin T
2016-09-02T16:21:14Z
Hi Thomas,

How do I get the variables of the filenames to substitute the bolded text in the formula?
thomas
2016-09-03T06:16:44Z
Hi. Im not at work the nest three weeks, so somebody else will have to show you.

Thomas
Gary_W
2016-12-23T16:54:00Z
In case you haven't fixed this already, here's a regex for you.

The word "Instruction" followed by zero or more any characters to the end of the string, replaced with "Instruction_Manual.pdf":
{REGEX(Replace|PSZLEDSTB3001 rev 1 Instruction 2P FL.PDF|Instruction.*$|Instruction_Manual.pdf)}

Replace one or more consecutive spaces with a single underscore (allows for fat-fingering of spaces which can be hard to see depending on the font):
{REGEX(Replace|PSZLEDSTB3001 rev 1 Instruction_Manual.pdf| +|_)}

Combine them (of course the actual text string should be replaced by a variable):
{REGEX(Replace|{REGEX(Replace|PSZLEDSTB3001 rev 1 Instruction 2P FL.PDF|Instruction.*$|Instruction_Manual.pdf)}| +|_)}
Scroll to Top