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.