I use this :
Code: Select all
@set var1="2011.01.15 "
@set var2=
@set var3=
@for %%i in (*.txt) do call :extra %%i
@goto :eof
:extra
@set var2=%1
@set var3=%var1%%var2%
@ren %var2% %var3%
@echo "-----"
D:\X>call :extra 0123.txt
"-----"
D:\X>call :extra 2222.txt
"-----"
D:\X>call :extra 3333.txt
"-----"
but...when the files are named 0123.txt, 0222.txt, 3333.txt, the for loop performs an extra iteration with the first file which
has already been renamed. Very strange.
D:\X>sol2
D:\X>call :extra 0123.txt
"-----"
D:\X>call :extra 0222.txt
"-----"
D:\X>call :extra 2011.01.15 0123.txt
Das System kann die angegebene Datei nicht finden. (can't find the file)
"-----"
D:\X>call :extra 3333.txt
"-----"
Why is this code allergic to a second file with a leading '0' character?