Copy files to Destination folders depending on filenames - VisualCron - Forum

Community forum

Markus Beier
2022-11-16T09:35:23Z
First of all I'm relativ beginner with VisualCron, so maybe sorry for the question..

I need help to get following task solved:
We need to copy files, to a destination folders depending on a part of the filename

Example.
I have PDF files an last part of the filename is the date (year/month/day)

FN4321b_20211231.pdf
FN123456z_20211231.pdf
FN1111111a_20200630.pdf
FN123123_20201231.pdf
FN123123o_20220331.pdf

Depending from the year part of the filename, the file should be copy to the right year folder like:

C:\Test\2020\FN1111111a_20200630.pdf
C:\Test\2020\FN123123_20201231.pdf

C:\Test\2021\FN4321b_20211231.pdf
C:\Test\2022\FN123456z_20211231.pdf

C:\Test\2022\FN987614i_20220331.pdf


Would be great if someone can help me
Thanks guys,
Markus
Sponsor
Forum information
Gary_W
2022-11-16T14:57:17Z
You don't say where exactly you need help but basically you'll create a job that
- lists the files
- loop through the list and for each file
-- get the year and save it in a variable
-- build a path to copy the file to using the saved variable
-- Copy the file

Note some of these steps can be combined but keep them separate while you are learning.
Here's a way to extract the year using a regular expression.
{REGEX(MatchGetGroup|FN4321b_20211231.pdf|FN.*_([0-9]{4})[0-9]{4}\.pdf|1)
In your job, the actual filename will be replaced by the variable {LOOP(CurrentValueXArray|0)} which is the current file in the loop. The regex matches as much of the filename as possible in order to stop false matches. Start with FN, followed by zero or more any characters until an underscore, then start the first remembered group of 4 digits, followed by 4 digits then a literal dot then pdf. If that is found return the first remembered group which will be the year. Save that into a variable that you can use in the destination path in the copy.

Hopefully that is enough to give you a push 🙂
Scroll to Top