Hello all,
I am attempting to write a batch file that will auto-move a file from a specific directory once it is created(e.g. if exists move file.png to backupfile.png)
My issue is to prevent the file from being over-written, as I need all iterations of the file saved into separate files, I would like to append either the system time or a number say 1,2,3 etc so that I have unique file names everytime.
I tried using the system time but cannot find a way to set this as a variable that I can append to the file name when it is moved.
Does anyone know how to do this?
Thank you,
Techy1984
Software/Hardware used:
ASKED:
October 11, 2012 5:13 PM
UPDATED:
October 11, 2012 5:45 PM
What is the operating system or scripting language that you want to use ?
Can you post your current code ?
The language is DOS on Windows XP through 8 I do tech support with rendering software and so I need to be able to capture each iteration of an image. So my though was to move the file to a new directory with a new name so as creating a visual log of the renders progress.My current code looks like this:@echo off
:A
for %%x in (%time%) do set %%x=%time%
move image.png “%UserProfile%\Desktop\Frames\%%x-image.png”
goto A
But all I get is a file called ‘-image.png’I will try jutpro’s suggestion but that looks like it should work.Thank you very much!
for %%x in (%time%) do set %%x=%time%
That command should start by building a list of files that it finds that have the name [%time%]. For every file with that name, it sets variable %%x to hold the value [%time%]. Then it uses the variable %%x to do the SET that sets the value of %%x to equal %time%. (Yes, the way it’s coded, it will try to do it twice — once for the IN() and again for the SET.)
Now, if there are no files named [%time%], it skips the SET and goes on to the MOVE command. Of course, in that case, %%x never gets a value assigned to it.
That’s how I read the FOR command. Does that make sense?
Tom
“That command should start by building a list of files…”
As far as I remember, a DOS’ FOR loop does not necessarily involve files. It can work on lists of many kinds of elements, and in this case I don’t think the intention is to loop through a list of files, but I don’t understand the real intention either.
Techy1984, can you explain your current code ? Anyway, the %time% variable holds the system time in ‘hh:mi:ss.ms’, which is includes characters not allowed in file names, so the format needs to be modified before renaming the file (something that jutpro’s code takes into account).
jutpro’s solution worked flawlessly! Thank you very much. I was able to create the following batch file:
@echo off
:A
set DATETIME=%date:~-4,4%%date:~-10,2%%date:~-7,2%%HOUR%%time:~0,2%%time:~3,2%%time:~6,2%
move render.png “%UserProfile%\Desktop\Frames\%DATETIME%_render.png”
goto A
carlosdl: The intent was simply as mentioned in my second post. I am rendering a scene in a rendering program. The program has the ability to automatically save the latest pass/iteration of the scene to an image file.However, it can only overwrite the same file not create a new file with every pass. I wanted to show a progressive set of images/frames for the render so my thought was to move the file and rename it to a unique and sortable file name so that each new pass is saved into it’s own file. jutpro’s code allowed me to do this using the batch loop I posted.Thank you all for your input this is why I like this site when I am stuck with no google-able answers =)
Great.
Thanks for the feedback.
Good job. I am glad I was able to help.