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


anderz
2017-01-10T13:00:26Z
I have a huge collection of .pdf files I want to compress to .zip files according to information found in the filename of the original files.
Example: I want all files that has 20161228 in their filename, like BUAB_20161228_1_01_007.pdf , to be appended to a .zip file with the name BUAB_20161228_1.zip.
One possible way would be to move or copy the file to folders named with parts of filename prior to compressing them.
I suppose this can be achieved using variables in VisualCron. Can anyone point me in the right direction.
Thanks
Sponsor
Forum information
Gary_W
2017-01-10T16:54:11Z
If I am understanding your request and you are looking to match "20161228" in filenames that end in ".pdf" here's a regular expression that will help:
{REGEX(Match|BUAB_20161228_1_01_007.pdf|^.*20161228.*\.pdf)}
Of course the actual filename would be replaced by a variable of the current filename as you loop through the files. The regular expression looks for the string "20161228" in the filename of a .pdf file. You can get more descriptive and tighten up the matching if the files always follow the pattern you gave in the example to make sure you don't grab a file by accident just because it's name contains the same string.
i.e. this regular expression: ^[A-Z]{4}_20161228_\d_\d{2}_\d{3}\.pdf
Matches the beginning of the line, followed by a character class of an uppercase letter with an indicator showing we want 4 of the previous type of character (so 4 uppercase characters), followed by a literal underscore, followed by the literal 20161228, an underscore, a digit, an underscore, 2 digits, etc.

Hope this helps.

Oh note that in this example the regex matches lowercase "pdf". VisualCron's regex engine is non-standard in that normally one can indicate an OR by using a pipe symbol. I tried using a group of (pdf|PDF) to match on upper or lowercase pdf but it failed since VisualCron reserves the pipe for the argument separator and the paren for the function closing symbol, even when escaped. I could not seem to find any info on alternate characters to use for this which limits the regex functionality somewhat. I suppose before looping through the files you could do a rename in the directory and ensure all extensions are lowercase or something if necessary.
Jon Tofte-Hansen
2017-01-11T11:47:19Z
You can do this (if all target file names should be cropped the 11 last characters in the zip file name including extension):

NB: Test thoroughly. There might be bugs.

Create two tasks in the job:
1: A "List file(s)" task for listing the relevant files (enter details in [Folder] and [Include file mask])
2: An "Archive - compress" task that iterates through the list with a "For each x in y" loop

In your particular case you can:

In [Archive settings]:
a: set the [Archive path] by removing the last 11 chars of the file name including extension:
<path to zip-file>\{STRING(Replace,{PATH(GetFileName|{LOOP(CurrentValueXLine)})},{STRING(Right|{PATH(GetFileName|{LOOP(CurrentValueXLine)})}|11)},)}.zip
b: set [Append to archive]

In [Content]:
a: set [Location]/[Folder] = {PATH(GetDirectoryName|{LOOP(CurrentValueXLine)})}
b: set [Location]/[Include file mask] = {STRING(Replace,{PATH(GetFileName|{LOOP(CurrentValueXLine)})},{STRING(Right|{PATH(GetFileName|{LOOP(CurrentValueXLine)})}|11)},)}*.pdf
(get all pdf's having the same name until the last 11 chars including extension)
(c): in [Item settings] you can click [Delete source file after]

Loop:
a: On the job page click the [Tasks] tab
b: Click [Add loop]
c: Set the above archive task in both start and end
d: In [Loop settings] choose [For each x in y]
e: Set [For each row x in] = {TASK(PrevTask,StdOut)}


There might be a more clever and stable way to crop the file name, but I couldn't find more suitable variables for that.
Scroll to Top