2

In Windows XP, I'm trying to figure out how to batch rename and remove the last characters of filenames.

Example of removing last 4 characters before file extenstion: file.doc.pdf --> file.pdf

I could do:

ren *.pdf *.
ren *.doc *.pdf

Though this wouldn't work well if there are already other PDFs in the folder.

Not sure if the FOR command is needed here.

Infinite loop
  • 39
  • 1
  • 1
  • 5

4 Answers4

2

ren * *. -> will give you 'file.doc' repeat above command -> will give you 'file' ren * *.pdf -> will give 'file.pdf'

Zimba
  • 1,291
2

If your file names do not contain any periods other than at the end (.doc.pdf), the following will work:

for /f "delims=." %a in ('dir /b *.doc.pdf') do ren "%~a.doc.pdf" "%~a.pdf"
Karan
  • 57,289
0
ren *.doc.pdf ????????????????????.pdf

Just make sure the target mask has at least as many ? as the longest base file name.

For an explanation as to why this works, see How does the Windows RENAME command interpret wildcards?

dbenham
  • 11,794
-1

file.doc.pdf --> file.doc:

for %I in (*.doc.pdf) do rename "%~nI.pdf" "%~nI"

file.doc --> file.pdf

for %I in (*.doc) do rename "%~nI.doc" "%~nI.pdf"
STTR
  • 6,891