Windows – How to batch rename and remove last characters

renamewindows

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.

Best Answer

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"
Related Question