We help IT Professionals succeed at work.
Get Started

Batch rename files sequentially and move

Rob Rudloff
Rob Rudloff asked
Last Modified: 2017-04-06
Hi.  I need help writing a batch file ..

I have randomly-named .jpg files in a folder (it's always C:\TEMP).  
I would like to rename these files to a argument that I pass, but add a sequential number (preferably sorted by file datetime).  
Then, the files would be moved to a folder that is passed in another argument (folder exists, and it's name is based on the current month, so it will always be in format "F:\PICS\yyyy-mm".

SO, I'd call something like:   RENAME.BAT "MyPicture"
and the files would be renamed and moved:
"C:\TEMP\bbb.jpg"    2017/04/03 13:45:45  --- >   "F:\PICS\2017-04\MyPicture-01.jpg"
"C:\TEMP\aaa.jpg"    2017/04/03 13:46:01  --- >   "F:\PICS\2017-04\MyPicture-02.jpg"
"C:\TEMP\ggg.jpg"    2017/04/03 13:47:01  --- >   "F:\PICS\2017-04\MyPicture-03.jpg"
"C:\TEMP\ddd.jpg"    2017/04/03 13:47:02  --- >   "F:\PICS\2017-04\MyPicture-04.jpg"

Open in new window

I was able to create the path based on the date, with something like:
set yyyy=%date:~-4%
set mm=%date:~4,2%
set FolderName= F:\PICS\%yyyy%-%mm%

Open in new window

But, I got stuck on the sequential renaming bit,  Any ideas?
-- thanks!
Watch Question
Test your restores, not your backups...
Expert of the Year 2019
Distinguished Expert 2020
This problem has been solved!
Unlock 2 Answers and 7 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE