问题
I have a this folder where I keep all my .ild files. problem is that they should all be numbered, and I need a batch script to do this.
I keep all my ilds in the folder ILDS.
Right now I have these 3 files in the "ILDS" folder:
09.ild
test.ild
s p a c e d.ild
How can i rename them, so they will be named:
1.ild
2.ild
3.ild
Thanks!
回答1:
You can loop over them and rename them
setlocal enabledelayedexpansion
set /a num=1
for %%a in (*.txt) do (
ren "%%a" "!num!%%~xa"
set /a num+=1
)
回答2:
@echo off
setlocal disableDelayedExpansion
pushd "c:\somePath\ilds"
set "N=0"
for %%F in (*.ild) do (
set "file=%%F"
setlocal enableDelayedExpansion
set /a N+=1
ren "!file!" "!N!.ildnew"
endlocal
)
ren *.ildnew *.ild
popd
The rename must be done in two steps because a given number.ild may already exist.
Note: The script can be run multiple times, but once there are 10 or more files, the numbers will be reassigned each time it is run. In other words, the file that is named 1.ild the first time will not be the same file after the second run.
来源:https://stackoverflow.com/questions/14583695/continuous-numbering-of-files-with-bat-file