English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

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

2007-04-19 14:31:46 · 3 answers · asked by Crocodilian 2 in Computers & Internet Software

3 answers

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"

2007-04-22 06:29:19 · answer #1 · answered by Kevin 7 · 3 0

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.

2007-04-19 14:41:05 · answer #2 · answered by Anonymous · 0 2

locate . -form f | together as examine FNM; do mv ${FNM} `head -a million ${FNM} | decrease -b fifty six-sixty 4`; carried out this could desire to artwork in bash. If on living house windows, bash is a factor of Cygwin. before definitely working this, you're able to be able to desire to choose to attempt it. replace "mv" with "echo mv" and it will tutor you the instructions it may execute. The 'fifty six-sixty 4' specifies bytes fifty six by way of sixty 4 of the 1st line of the record. in case you get the incorrect piece, you're able to be able to could desire to regulate the 1st and 2d numbers.

2016-11-25 23:19:55 · answer #3 · answered by ? 4 · 0 0

fedest.com, questions and answers