How do I rename a bunch of files in the Command Prompt?
Solution 1:
I've been loving the command line since the mid 80's but I have to admit this is one area where I always rely on Rename-It! I know you want DOS but I'll leave this one just in case someone stumbles through that hasn't heard of it.
During times when I needed extreme control over individual files (usually in groups) I have used a spreadsheet to build the batch file. In this case I use DIR/B to collect file names into a text file, paste them into one column, build the renaming command in a final column (D in this case) then paste that column into a .BAT file and run it.
Solution 2:
The following Batch file do what you want:
@echo off
setlocal EnableDelayedExpansion
set i=0
for %%a in (*.jpg) do (
set /a i+=1
ren "%%a" "!i!.new"
)
ren *.new *.jpg
Files are first renamed with .new
extension to avoid conflicts with the files being processed and then renamed back to .jpg
at end.
Solution 3:
You can use ReNamer and define any logical rules you want. Delete, Replace, Cleanup, Regex, Insert meta tags, even script out your custom rule.
Below is an example of rules for renaming sequences of images from the digital camera:
- Delete: Delete from Position 1 until the End (skip extension)
- Insert: Insert "New Name " as Suffix (skip extension)
- Serialize: Serialize Incremental from 1 step 1 repeat 1 and pad to length 3 as Suffix (skip extension)
Solution 4:
This will do what you want from the command line, using a batch file:
@echo off
SET COUNT=1
SET PREFIX=Photos
FOR /f "tokens=*" %%G IN ('dir /b *.jpg') DO (call :renum "%%G")
GOTO :eof
:renum
ren %1 %PREFIX%_%count%.jpg
set /a count+=1
GOTO :eof
Based on some example code at SS4.