1. Home >
  2. Computers & Internet >
  3. Software >
  4. Resolved Question
Crocodilian Crocodil...
Member since:
May 16, 2006
Total points:
928 (Level 2)

Resolved Question

Show me another »

Batch rename to alter suffix in WinXP?

I've got a bunch of files, which have accumulated a supplementaty .html file name. They're other kinds of files, eg

Movie.avi.html -- is actually an AVI file
Movie2.wmv.html -- is a windows media file
Report.pdf.html -- is an Acrobat file

-- but they've all got these .html suffixes stuck on them (they were posted to a website internally)

how can I batch rename, preserving the original filename, but deleting the suffix? I've looked at the DOS/Console REN command -- is there some kind of wild card trick to it? or is there something else?

I'm running WinXP
  • 3 years ago
Kevin by Kevin
Member since:
January 30, 2006
Total points:
231303 (Level 7)

Best Answer - Chosen by Voters

No problem. You can do this with the DOS "ren" command with a little modification.

Assuming that all of your files that you want to rename follow the format that you have given,

filename.ext.html

Open a DOS command prompt, change to the directory with the files that need to be renamed, and then, on One commandline enter the following,

for /f "tokens=1-3 delims=." %i in ('dir *.html /b') do ren "%i.%j.%k" "%i.%j"

Basically, this is parsing the "dir" command with some conditions and then passing the results to the "ren" command.

- for /f "tokens=1-3 delims=." %i in
A token is a part of an output. In this case it will be the output of the dir command. It will use the period as a delimiter for the different tokens in the output. So a filename like test.txt.html will have three tokens "test" "txt" and "html" which will be assigned to %i, %j, and %k variables, respectively.

- ('dir *.html /b')
The parsed pieces of the output of this command will be used for the input of the "ren" command

- do ren "%i.%j.%k" "%i.%j"
Based on the tokens, delims, and variables of the first part of this commandline, a filename of test.txt.html come through this line as,

ren "test.txt.html" "test.txt"

Which is what you need. The quotes are included to handle any long files names or spaces in file names.

If you want to see what the command will do without actually running the "ren" command, then put an "@echo" command in front of the "ren" so that the commands will be echo'ed to the screen without actually doing anything.

That would look like, all on one line,

for /f "tokens=1-3 delims=." %i in ('dir *.html /b') do @echo ren "%i.%j.%k" "%i.%j"


Then, again, to actually run the command, remove the @echo,

for /f "tokens=1-3 delims=." %i in ('dir *.html /b') do ren "%i.%j.%k" "%i.%j"

Source(s):

Many years working with DOS.
  • 3 years ago
100% 2 Votes

There are currently no comments for this question.

Other Answers (1)

  • Colinc by Colinc
    Member since:
    March 14, 2007
    Total points:
    117326 (Level 7)
    There is no safe way to batch this in Windows. Windows is still half convinced that any file must have 8 characters before the dot and 3 after (dos rules), seriously it does not play well with additional dots.
    Someone recently lost all their files from photoshop and illustrator, turned out they had included a dotted date in the name. Half the name did not show, and the extensions dumped.
    • 3 years ago
    0% 0 Votes

Answers International

Yahoo! does not evaluate or guarantee the accuracy of any Yahoo! Answers content. Click here for the Full Disclaimer.

Help us improve Yahoo! Answers. Send Feedback