Page 1 of 1

rename

Posted: 22 Dec 2010 03:33
by glob5
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)

Re: rename

Posted: 22 Dec 2010 03:47
by glob5
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)

Re: rename

Posted: 22 Dec 2010 07:18
by ChickenSoup
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
)