Rename file with variable

I’m trying to use the Rename File action with a variable in the new name. But it always fails with “Rename failed: The system cannot find the path specified”. As soon as I take the variable out of the new name, it works.

Example:

Set DDMMYYY into a variable called %Date_today%
Rename {
Existing file = abc.txt
New Name = Log_%Date_today%.log}

From testing here this shouldn’t be occurring, however its always best to specify the full path to the existing file. This may be causing problems as its using the applications current path (which could be anything depending on previously run actions).

Jason,

Thanks for your response.

The existing file does have it’s full path listed, I just didn’t do that in the shorthand I wrote. I should have just sent screenshots from the beginning. I’ll attach screenshots this time, as well as the project file.

Not only does Rename Files seem to buck at having variables in the file name, but also Create Zip File. See the error for Create Zip File, I think it’s trying to put slashes in there, when I do not have that defined at all.

Here are screenshots and project file.

Acutally, I don’t think it’s letting me attach anything… it’s a jpeg, not sure why? I attached a jpeg to a different thread before.

Hi Katie,

When you upload images, in the attachment list there is a link next to it to insert the image in the post.

Attachment unavailable

Hi Katie, 

So I have reproduced the error you were seeing. It is potentially due to the formatting set on the date variable. By default this is set to “c” which is defined as “ShortDateFormat + LongTimeFormat” which results in “dd/mm/yyyy hh:mm:ss” (this is locale based). Therefore the days, months and years are treated as folders to look under to write the renamed file to. 

To solve this issue simply change the formatting of the date variable to the format you require, and keep the formatting in the date set action. 

Lastly I suggest reviewing errors in the context of the whole script. Typically the action shows the parameters it was called with and the expansion of any variables. In this case that is how I determined what was going on. 


Attachment unavailable

Ok, changing the date format on the variable itself (from Edit Variable screen) from c to MMDDYYY did seem to fix the error. But it’s writing the correct date out. I can see from the log, it’s putting the correct date into the variable, but when the rename action or the write to text file action calls that variable… it’s using some other weird date.

Also, can you help me understand why we have to set the date format in two places: the “Edit Variable” screen and the “Get Date/Time action”? I noticed that if they’re different formats (Ex: Variable set to MMDDYYY and GetDate Action set to MMYYYY), it uses the GetDate format when writing to the variable, it seems to ignore the format in the Edit Variable screen.\


Attachment unavailable

Typo from previous post: Its NOT writing the correct date out.

So if I change my variable to a String or an Integer, then it DOES write the correct date out.

So that begs the question, what’s going on when I use the Date/Time variable type and when would you want to use it?

Hi Katie,

The behaviour you have found is correct. Strings are required to be used when choosing only part of the date time value to get. When using a date time variable the format string needs to include all the information of the date time (such as the “c”) format string, otherwise the conversion does not work and an incorrect date is the result.

I have logged a support case to fix get date time so that when using a date variable the format string is not used. This will then mean the full date time value is passed to the variable.