Community forum

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


hjohnson
2018-11-30T16:00:20Z
I am looking at incrementing part of a filename, only if, it is a new version being created after the initial creation at the beginning of the month.

Tasks for the job so far are:
1: job report - to see if the job has been run yet this month
2: create a variable out of the date of the last run of the job
3: run a script via command line to create the monthly files.
4: Zip up the newly created files, as they need to be in one particularly named zipped file.
5: rename the zip file to what is needed (XXX_(creation date)_V01.zip) *the V01 is what needs to possibly be incremented.
6: get the name of the zipped file
7: create a fileName variable with the zipped files' file name.

The initial job is set to run the 5th of every month. If I have to run it again after that, the V01 needs to be incremented to ie V02 and so on. How would I go about doing this? Should I be checking the last run date later and of a specific task? Should I use a loop? Any possible ways would be greatly appreciated.

Thanks!
Sponsor
Forum information
Gary_W
2018-11-30T22:09:44Z
This will do the version incrementing although it's kind of fugly because the nested functions make it real difficult to read.

{REGEX(Replace|XXX_20181130_V01.zip|V\d+|V{MATH(Add|Integer|{REGEX(MatchGetGroup|XXX_20181130_V01.zip|_V(\d+)\.zip|1)}|1|00)})}
XXX_20181130_V02.zip

The inner regex MatchGetGroup isolates the version number with a regular expression (capture the group of 1 or more numbers after the "_V" but before the ".zip"), then the surrounding math add integer adds one to it while formatting with a leading "0". Then the replace regex looks for "_V" followed by 1 or more digits and replaces that with "_V" and the result from the first sentence. You will have to replace the actual filename with the variable for it once you figure that part out.

I hope this helps somewhat.

Gary
jrtwynam
2018-12-06T14:57:25Z
Alternatively, you could try something like this:


  1. Set Job Variable "Version number" = 1.
  2. Set Job Variable "File Exists" = True (i.e. start by assuming the file exists, so that it can get into the loop).
  3. Loop while Job Variable "File Exists" = True:
  4. --Pad "Version Number" with leading zeroes to 2 characters in length (result = "01").
  5. --Set Job Variable "Desired File Name" based on your naming convention, using the "Version Number" job variable.
  6. --Set Job Variable "File Exists" using the constructed file name as well as VC's {FILE(Exists| function.
  7. --Increment the "Version number" variable by 1. No need for an "if"... if the previous version didn't exist, then our file name is already set.
  8. End Loop.
  9. Final result should be the file name with the next available version number.


This method adds extra steps to the process, but I find it easier to read and understand than the RegEx method. Plus, what you could do is break this off into a separate job with appropriate job variables so that this same logic can be re-used for other jobs (assuming you have other jobs with the same requirement).
Scroll to Top