Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I'd like automate a bulk renaming task with just one click or with a command. I suppose I need command line utility or a batch file that allows me to do this. The changes in all couples are the same: adding a prefix "DM-" to the files names in one case, and removing the prefix in the other so as to restore the original names. Could you help me out with this? Thanx.
ADD PREFIX DM- TO CTF-*.* = DM-CTF-*.*
REMOVE PREFIX DM- FROM DM-CTF-*.* = CTF-*.*ADD PREFIX DM- TO BR-*.* = DM-BR-*.*
REMOVE PREFIX DM- FROM DM-BR-*.* = BR-*.*ADD PREFIX DM- TO AS-*.* = DM-AS-*.*
REMOVE PREFIX DM- FROM DM-AS-*.* = AS-*.*ADD PREFIX DM- TO DOM-*.* = DM-DOM-*.*
REMOVE PREFIX DM- FROM DM-DOM-*.* = DOM-*.*ADD PREFIX DM- TO ONS-*.* = DM-ONS-*.*
REMOVE PREFIX DM- FROM DM-ONS-*.* = ONS-*.*ADD PREFIX DM- TO VCTF-*.* = DM-VCTF-*.*
REMOVE PREFIX DM- FROM DM-VCTF-*.* = VCTF-*.*

Try these:
:: noDM.bat
@echo offfor %%D in (DM-*.*) do call :noDM- %%D
goto :eof:noDM-
set Dname=%1
ren %1 %Dname:~3,8%
goto :eof
:: DONE###
:: DM.bat
@echo offfor %%D in (*.*) do call :DM- %%D
goto :eof:DM-
ren %1 DM-%1
goto :eof
:: DONEYou'll want to put the BATs in another directory, so they don't get renamed and confuse the issue.
If at first you don't succeed, you're about average.M2

Thanx very much for your answer. Your skills with batch files is outstanding. I've tried this and the fist bat works fine, except for the VCTF*.* files which are not renamed. The second batch doesn't work as expected. ?¿

Sorry I meant the second one works (the one for renaming files). The one which doesn't work at all is the one for restoring them.

The noDM.bat only looks for files named DM-*.*
Are ther files of that spec in the directory?
If so, post a few of the exact names.
If at first you don't succeed, you're about average.M2

OK. The bat for renaming:
for %%D in (*.*) do call :DM- %%D
goto :eof:DM-
ren %1 DM-%1
goto :eofThe bat for restoring:
for %%D in (DM-*.*) do call :noDM- %%D
goto :eof:noDM-
set Dname=%1
ren %1 %Dname:~3,8%
goto :eofAnd the files with which I'm testing:
AS-mapa1.txt
BR-mapaconnombremuylargo.txt
CTF-estoesunmapa.txt
CTF-mapa.txt
CTF-mapaconnombremuylargo.txt
DM-mapa1.txt
DM-mapa1connombremuylargo.txt
DM-nombre-de-un-mapa.txt
ONS-mapaconnombremuylargo.txt
VCTF-unmapa1.txt
TUT-DM.txt
TUT-BR.txtWith the bat for renaming all take the -DM prefix, except for TUT-DM.txt and TUT-BR.txt (it's correct: these files must not be renamed (I placed there just to be sure). However, VCTF-DM.txt keeps the same and no prefix is added, which is not right.
The bat for restoring create a little disaster: some files loose their extensions with this result:
ONS-mapa
DM-nombr
DM-mapa1
DM-DM-mapa1connombremuylargo.txt
DM-CTF-mapaconnombremuylargo.txt
CTF-mapa
CTF-esto etc.Could you please check it out?
It's important that only the first 3 letters are removed with the second bat (DM-) so as to leave the files with their original names. So, DM-CTF-file.txt should revert to CTF-file.txt, and DM-DM-file should become DM-file.txt, ok?
Thank you very much and excuse my persistance.

Persistence is good. It gets things done.
Try these two:
:: addDM2.bat
@echo offfor %%D in (*.*) do call :DM- %%D
goto :eof:DM-
set workfile=%1
if /i %workfile:~0,3%==DM- goto :skip
ren %1 DM-%1
:skip
goto :eof
:: DONE
==================
:: noDM2.bat
@echo offfor %%D in (DM-*.*) do call :noDM- %%D
goto :eof:noDM-
set Dname=%1
ren %1 %Dname:~3,80%
goto :eof
:: DONE
::
If at first you don't succeed, you're about average.M2

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |