rename

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
glob5
Posts: 34
Joined: 23 Nov 2010 00:47

rename

#1 Post by glob5 » 22 Dec 2010 03:33

my bat file has these two for loops for copying files and moving folders. Need to modify them
to rename files and folders that already exist in the destination with a time stamp before copying and moving the sources. :?

for /f "tokens=* delims= " %%f in ('dir/s/b dira\*.bin ^|find /v "DDD"') do (copy "%%f" dirb)

for /f %%d in ('dir /b /ad "dirC"') do (move /y dir1\%%d dirD)

glob5
Posts: 34
Joined: 23 Nov 2010 00:47

Re: rename

#2 Post by glob5 » 22 Dec 2010 03:47

my bat file has these two for loops for copying files and moving folders. Need to modify them
to rename files and folders that already exist in the destination with a time stamp before copying and moving the sources. :?

for /f "tokens=* delims= " %%f in ('dir/s/b dira\*.bin ^|find /v "DDD"') do (copy "%%f" dirb)

for /f %%d in ('dir /b /ad "dirC"') do (move /y dirC\%%d dirD)

ChickenSoup
Posts: 79
Joined: 13 Dec 2010 10:32

Re: rename

#3 Post by ChickenSoup » 22 Dec 2010 07:18

I think this should do it:

Code: Select all

for /f "tokens=* delims= " %%f in ('dir/s/b dira\*.bin ^|find /v "DDD"') do (
   if exist %%f rename %%f %%f%DATE:~-4%-%DATE:~4,2%-%DATE:~7,2%
   copy "%%f" dirb
)

for /f %%d in ('dir /b /ad "dirC"') do (
   if exist %%d rename %%d %%d%DATE:~-4%-%DATE:~4,2%-%DATE:~7,2%
   move /y dirC\%%d dirD
)

Post Reply