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


PeterW
2013-01-08T21:13:20Z
Hello,

I'm guessing this will be an easy question but I cannot get this to work. I have a job that downloads multiple files to a folder and then attempts to append the date/time to the end of the file name.

The file mask for the rename looks for files that match '??.FINALS.DCP.OUTPUT????????' and when I go to the test tab and click the 'Show filtered files' button it successfully displays all 11 files currently sitting in the folder.

For the rename settings I have it set to '*.{DATEFORMAT(yyyyMMddHHmmss)}' which is where I would expect it to take the file name and append '.YYYYMMDDhhmmss' to the end. However when it runs it takes the first file in the folder and renames it to 'NE.FINALS.DCP.YYYYMMDDhhmmss'. So it strips off the 'OUTPUT????????' and appends the date/time then throws an error saying: Exception in Task: Cannot create a file when that file already exists.

Does anyone know what I am doing wrong?

Thanks,

Peter
Sponsor
Forum information
bbusse
2013-01-08T22:06:02Z
I'm not sure if you can do multiple files like that or not, never tried. However, what I typically do when I want something to happen to multiple files, I use a loop.


So your Job, if your only goal was to rename files, would consist of 2 tasks, and a loop. You use the output (list of files) from the "List Files" task, and go through each item one by one in a loop doing a Rename Files task.

1. Create New blank Job
2. Create "List Files" task, much the same way you did for your "Rename file" task with the same file mask, etc...
3. Create a "Rename File" task, and this is where the fun comes in 🙂
4. Create a Loop that just loops on the Rename File task above.

Assuming all my files are located in this path (VERY VERY VERY Case Sensitive). Case needs to match on both the List Files and the Rename tasks.

Path: d:\temp\Rename\

So, Create your "List Files" task as I mentioned. Then, create the "Rename file" task. The Rename File task will have the same exact folder as your List Files task, in my case "d:\temp\Rename".

The Real fun part though, is the "Include File Mask". Use this, substituting your path for what I have, separated by \\ instead of single \ :
{REGEX(Replace|{LOOP(CurrentValueX)}|d:\\temp\\Rename\\|)}

What that does, is it takes the current value in the loop, and strips off the path, leaving only the file name :)

Now, go to your "Rename Settings" tab in the Rename File task. Leave the asterisk * on the 'New Name Mask' and check the box for "Post process mask with Variable"
Assuming you want whatever the file name was EXACTLY, appended with .20130108154700 at the end (or whatever the current time is, you'd use this String replace forumla:

{STRING(Replace|{NEWNAME()}|{NEWNAME()}|{NEWNAME()}.{DATEFORMAT(yyyyMMddHHmmss)})}

Now, it looks scary, but its very simple. Its a basic string replace. The first instance of 'NEWNAME' listed is the string you want to modify. The 2nd instance of 'NEWNAME' is what part of 'NEWNAME' you wanted to replace, in this case I wanna replace all of it. The 3rd instance of 'NEWNAME' is how I want whatever I replaced to look. So, I still want to use the entire name of 'NEWNAME' and add .{DATEFORMAT(yyyyMMddHHmmss)} Which you already know.

See the screenshots lol. They'll help :)

Now, edit the job and go to the 'Tasks' tab. You should see your list files and your rename file tasks. Click the 'Add Loop' button. Name it whatever you want and make sure your rename task is listed in both dropdowns. Click the 'Loops Settings' tab.

Select the radio button for "For each x in y" and on the first line, put this:
{TASK(PrevTask,StdOut)}

What that does is takes the Previous task (your List Files) and uses its 'StdOut' output as the input. Press OK and save the loop, and then save the job.

Thats it, technically. I have screenshots, in order (skipped a few obvious steps i noted)






bbusse attached the following image(s):
PeterW
2013-01-09T13:56:22Z
Well, I'm glad I asked because I would have never figured that out by myself! 😁

I set it up just as you described and it worked perfectly. Thank you for your help!

Regards,

Peter
bbusse
2013-01-09T19:12:30Z
You're very welcome. I know I was scared (couple months ago) to start looking into using loops, but Henrik (i assume thats him 😉 ) was kind enough to have video tutorials under the 'Support' tab above. Although it doesn't cover what it is you wanted, it helped me at least understand how to take output from one task and use it in another, including loops.

VERY helpful.

Henrik, I know the process I described does handle renaming multiple files. And because it is singular, the "Rename File" task does, to me anyway, imply that its just for renaming ONE file at a time. Is there a chance you could add to this and make a 'Rename Files' task that can do what I did, all by itself?

Brian
barisumutlu
2017-04-22T13:02:48Z
Originally Posted by: bbusse 

I'm not sure if you can do multiple files like that or not, never tried. However, what I typically do when I want something to happen to multiple files, I use a loop.


So your Job, if your only goal was to rename files, would consist of 2 tasks, and a loop. You use the output (list of files) from the "List Files" task, and go through each item one by one in a loop doing a Rename Files task.

1. Create New blank Job
2. Create "List Files" task, much the same way you did for your "Rename file" task with the same file mask, etc...
3. Create a "Rename File" task, and this is where the fun comes in 🙂
4. Create a Loop that just loops on the Rename File task above.

Assuming all my files are located in this path (VERY VERY VERY Case Sensitive). Case needs to match on both the List Files and the Rename tasks.

Path: d:\temp\Rename\

So, Create your "List Files" task as I mentioned. Then, create the "Rename file" task. The Rename File task will have the same exact folder as your List Files task, in my case "d:\temp\Rename".

The Real fun part though, is the "Include File Mask". Use this, substituting your path for what I have, separated by \\ instead of single \ :
{REGEX(Replace|{LOOP(CurrentValueX)}|d:\\temp\\Rename\\|)}

What that does, is it takes the current value in the loop, and strips off the path, leaving only the file name :)

Now, go to your "Rename Settings" tab in the Rename File task. Leave the asterisk * on the 'New Name Mask' and check the box for "Post process mask with Variable"
Assuming you want whatever the file name was EXACTLY, appended with .20130108154700 at the end (or whatever the current time is, you'd use this String replace forumla:

{STRING(Replace|{NEWNAME()}|{NEWNAME()}|{NEWNAME()}.{DATEFORMAT(yyyyMMddHHmmss)})}

Now, it looks scary, but its very simple. Its a basic string replace. The first instance of 'NEWNAME' listed is the string you want to modify. The 2nd instance of 'NEWNAME' is what part of 'NEWNAME' you wanted to replace, in this case I wanna replace all of it. The 3rd instance of 'NEWNAME' is how I want whatever I replaced to look. So, I still want to use the entire name of 'NEWNAME' and add .{DATEFORMAT(yyyyMMddHHmmss)} Which you already know.

See the screenshots lol. They'll help :)

Now, edit the job and go to the 'Tasks' tab. You should see your list files and your rename file tasks. Click the 'Add Loop' button. Name it whatever you want and make sure your rename task is listed in both dropdowns. Click the 'Loops Settings' tab.

Select the radio button for "For each x in y" and on the first line, put this:
{TASK(PrevTask,StdOut)}

What that does is takes the Previous task (your List Files) and uses its 'StdOut' output as the input. Press OK and save the loop, and then save the job.

Thats it, technically. I have screenshots, in order (skipped a few obvious steps i noted)








{STRING(Replace|{NEWNAME()}|{NEWNAME()}|{NEWNAME()}.{DATEFORMAT(yyyyMMddHHmmss)})}

Why NEWNAME repeated three times there? what's the logic?
Scroll to Top