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:
Ah, excellent, Bill!
I modified it for a quick test, see below.
I put a hyphen before the !Count! so it named files like "MyPicture-1.jpg"
So, is there a way to format the !Count! to force a two digit number, like "MyPicture-01.jpg" ?
Can I return the value of Count back from the batch file?
Thanks!
Rob
@echo offsetlocal EnableDelayedExpansionset BaseDir=D:\TESTDATA\PicQueueset BaseName=%~1set yyyy=%date:~-4%set mm=%date:~4,2%set DestDir=D:\TESTDATA\%yyyy%-%mm%set Count=0for /f "tokens=*" %%A in ('dir /b /od "%BaseDir%\*.jpg"') do ( set /a Count += 1 move "%BaseDir%\%%~A" "%DestDir%\%BaseName%-!Count!.jpg")
That seems to do everything I need! (You are wise in the ways of "batch")
Now, I put this in a file called MovePics.bat and I call it like:
movepics.bat MyPics
It renames the 10 files in that folder properly (like MyPics-01.jpg, and so on) but I don't see a return value of 10.
Is there a trick to calling it from the command line to see the return code?
Thanks!
Rob
Bill Prew
In the calling BAT script, the return code is passed back in the %ERRORLEVEL% variable, just display or use it after the call to this bath file.
I modified it for a quick test, see below.
I put a hyphen before the !Count! so it named files like "MyPicture-1.jpg"
So, is there a way to format the !Count! to force a two digit number, like "MyPicture-01.jpg" ?
Can I return the value of Count back from the batch file?
Thanks!
Rob
Open in new window