troubleshooting Question

Batch rename files sequentially and move

Avatar of Rob Rudloff
Rob RudloffFlag for United States of America asked on
Windows BatchWindows OS
7 Comments2 Solutions222 ViewsLast Modified:
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"
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%
But, I got stuck on the sequential renaming bit,  Any ideas?
-- thanks!
Join our community to see this answer!
Unlock 2 Answers and 7 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros