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!
Request for bat file
Moderator: DosItHelp
Re: Request for bat file
batch one too?all files in the local directory (directory where the batch file is located)
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"
Last edited by !k on 10 Oct 2011 06:03, edited 1 time in total.
Re: Request for bat file
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!
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
ChangedAgent_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...
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
Run for /?what does "delims=" stand for?
and also what is %%~nxf?
Re: Request for bat file
I have no idea what u just did there but it works!
Thank you!
Thank you!