What I'm trying to do is create a batch file that will take the highest numbered file
eg.
Directory containing the files
Image 8.jpg
Image 9.jpg
Image 10.jpg
Image 11.jpg
and I want the batch to take the highest numbered file, in this case Image 11.JPG and move it to a new directory, then delete the rest. I have used xcopy in the form
XCOPY "C:\Test\Image *.jpg" "C:\Imaged\TEST.jpg /y
and it does exactly what I want, except it gives me a prompt if I want it as a (d)directory or (f)file? and I have to manually type F in order for it to complete, I need it to be totally automated. Any help is greatly appretiated!
Batch file with variables
Moderator: DosItHelp
-
- Posts: 40
- Joined: 25 Jan 2008 14:05
I am newbie to scripting, so I cannot give the script at this point, but at first glance at the question I believe your going to have to read each filename in that directory and then second parse the file names. Once you parse the filename you will need to separate the filename and the extension and then likely parse again to isolate the numeric in the filename (first part)...well there is more then likely an easier solutions but this gives you some starting point.
Dave,
Looks like your XCOPY relies on the processing order of files.
The concern jaffamuffin mentioned is valid:
Your XCopy command in fact copies all files on top of each other and TEST.jpg ends up to be the last file copied.
If "Image 11.jpg" for some reason is not processed last then TEST.jpg will not be "Image 11.jpg".
If you don't want to give up the simplicity of your approach and if the file you want TEST.jpg to be is always the one with the latest time stamp then you can script a bit more save by using the /D flag with your XCOPY like this:
It ensures that TEST.jpg will end up being the file with the latest time stamp.
Hope this is useful
Looks like your XCOPY relies on the processing order of files.
The concern jaffamuffin mentioned is valid:
Your XCopy command in fact copies all files on top of each other and TEST.jpg ends up to be the last file copied.
If "Image 11.jpg" for some reason is not processed last then TEST.jpg will not be "Image 11.jpg".
If you don't want to give up the simplicity of your approach and if the file you want TEST.jpg to be is always the one with the latest time stamp then you can script a bit more save by using the /D flag with your XCOPY like this:
Code: Select all
echo F|XCOPY "C:\Test\Image *.jpg" "C:\Imaged\TEST.jpg /y /d
It ensures that TEST.jpg will end up being the file with the latest time stamp.
Hope this is useful