Page 1 of 1
Request for bat file
Posted: 09 Oct 2011 18:34
by Agent_BK
I need a really simple bat file and I was hoping you guys could help me out.
this bat file should rename all files in the local directory (directory where the batch file is located) and all the subdirectories so that it would append a random number on the left of the filename.
Thanks!
Re: Request for bat file
Posted: 10 Oct 2011 04:01
by !k
all files in the local directory (directory where the batch file is located)
batch one too?
Code: Select all
for /f "delims=" %%f in ('dir /b/s/a-d ^|findstr /eiv /c:.bat /c:.cmd') do call ren "%%f" "%%random%%_%%~nxf"
Re: Request for bat file
Posted: 10 Oct 2011 05:14
by Agent_BK
amazing job
I have no idea how or why this works, but it does. Thanks!
I noticed something tho. If you run this from cmd it won't rename files in the directory where the .bat file is located but in the current directory in cmd.
It's not a problem tho since I'll be running it by double clicking.
errrm could you exclude the .bat file? I don't want it to have a random number in front... To make thing easier you can exclude all *.bat files... I tried it myself but failed big time

One more thing... If it's not too much of a trouble could you reverse the job? A script that would remove random numbers? I assume this would require modifying original script too. As I said if it's too much work don't bother
I am trying to understand your line... I partially understand it but...
what does "delims=" stand for?
and also what is %%~nxf?
Thank you for support!
Re: Request for bat file
Posted: 10 Oct 2011 06:11
by !k
Agent_BK wrote:errrm could you exclude the .bat file? I don't want it to have a random number in front... To make thing easier you can exclude all *.bat files...
Changed
One more thing... If it's not too much of a trouble could you reverse the job? A script that would remove random numbers?
Code: Select all
@echo off
for /f "delims=" %%f in ('dir /b/s/a-d') do call :back "%%f" "%%~nxf"
goto :eof
:back
for /f "tokens=1,* delims=_" %%a in ('echo:%2^|findstr /rbc:\^"[0-9][0-9]*_') do ren %1 "%%b"
goto :eof
what does "delims=" stand for?
and also what is %%~nxf?
Run
for /?
Re: Request for bat file
Posted: 10 Oct 2011 11:47
by Agent_BK
I have no idea what u just did there but it works!
Thank you!