Request for bat file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Agent_BK
Posts: 3
Joined: 09 Oct 2011 18:22

Request for bat file

#1 Post by Agent_BK » 09 Oct 2011 18:34

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!

!k
Expert
Posts: 378
Joined: 17 Oct 2009 08:30
Location: Russia

Re: Request for bat file

#2 Post by !k » 10 Oct 2011 04:01

all files in the local directory (directory where the batch file is located)
batch one too? :mrgreen:

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.

Agent_BK
Posts: 3
Joined: 09 Oct 2011 18:22

Re: Request for bat file

#3 Post by Agent_BK » 10 Oct 2011 05:14

amazing job :shock:
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 :wink:

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!

!k
Expert
Posts: 378
Joined: 17 Oct 2009 08:30
Location: Russia

Re: Request for bat file

#4 Post by !k » 10 Oct 2011 06:11

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 /?

Agent_BK
Posts: 3
Joined: 09 Oct 2011 18:22

Re: Request for bat file

#5 Post by Agent_BK » 10 Oct 2011 11:47

I have no idea what u just did there but it works!
Thank you!

Post Reply