Hi I'd like to create a bat file to rename files using the cmd. Say a friend and I went on vacation together. We have put all our pictures together and I now want to rename all the pictures in a sequence.
Say I selected the following pictures:
- mypicture_3435.jpg (file date = 01 Jan 2015 10:00)
- mypicture_3465.jpg (file date = 04 Jan 2015 12:00)
- myfriendspicture_2221.jpg (file date = 03 Jan 2015 12:00)
- myfriendspicture_2226.jpg (file date = 04 Jan 2015 11:00)
I would like to get the following output:
- ourvacation_01.jpg [mypicture_3435.jpg (file date = 01 Jan 2015 10:00)]
- ourvacation_02.jpg [myfriendspicture_2221.jpg (file date = 03 Jan 2015 12:00)]
- ourvacation_03.jpg [myfriendspicture_2226.jpg (file date = 04 Jan 2015 11:00)]
- ourvacation_04.jpg [mypicture_3465.jpg (file date = 04 Jan 2015 12:00)]
This is easy to do with specific software such as acdsee or even with Windows' image browser. But I would like to do it using the command promt. (I teach mathematics in a school and I would like to use this as a programming example).
I tried the follwing script and it worked:
@echo off setlocal EnableDelayedExpansion set i=0 for %%a in (*.jpg) do ( set /a i+=1 ren "%%a" "!i!.new" ) ren *.new *.jpg
But it renamed the files like this:
myfriendspicture_2221.jpg
becomes1.jpg
myfriendspicture_2226.jpg
becomes2.jpg
mypicture_3435.jpg
becomes3.jpg
mypicture_3465.jpg
becomes4.jpg
So the problems are:
- They do not keep a chronological sequence.
- If I have say 11 items, and sort them by name, the sequence runs 1, 10, 11, 2, 3, 4...
I tried to run dir /od before I rename, but it didn't work, the sequence runs according to the file name.
All the strings I have found regarding this issue append the current date and time to the file name, but not the file date and time to it's own name.
I couldn't find a way to add a leading 0 or 00 to the sequence so that the file name and chronological order match.
Thank you very much in advance for the help.