Batch traverse subolders and rename files -
i traverse folder , it's subfolders, keep counter variable of current file , rename $counter$existingfilename.
e.g.
$count = 1; foreach $file in $folder { $file.name = $count + $file.name; $count++; }
the person can answer hero! :)
btw using windows 7.
all right, while pondering on questions in comment post (or maybe still making way site read them), here's trial shot:
@echo off set "rootdir=%~1" if "%rootdir%"=="" set rootdir=. set cnt=0 /r "%rootdir%" %%f in (*) ( set /a cnt+=1 setlocal enabledelayedexpansion rename "%%f" "!cnt!%%~nxf" endlocal )
this rename files prepending names numbers, this:
1file.txt 2program.exe ...
if like, can have way:
00001file.txt 00002program.exe
for you'll need make 2 changes above script (highlighted in bold):
@echo off set "rootdir=%~1" if "%rootdir%"=="" set rootdir=. set cnt=10000 /r "%rootdir%" %%f in (*) ( set /a cnt+=1 setlocal enabledelayedexpansion rename "%%f" "!cnt:~1!%%~nxf" endlocal )
Comments
Post a Comment