I need to copy some directories from the network to my machine and remove the extension .nary from the files in the copied folders; so a file myFile.doc.nary will become myFile.doc. I've got the following Windows batch file, but don't know how to limit the rename to the two folders if the batch file is run from c:\:
xcopy /s \\some_server\MYFOLDER1 c:\MYFOLDER1\
xcopy /s \\some_server\MYFOLDER2 c:\MYFOLDER2\
for /r %%x in (*.nary) do (
ren "%%x" *.
)
pause
How do you limit the rename to those two folders on c:\? Also, is it possible to not run the copies if the folders are already on my machine's c:\? Thank you.
c:\?Just use for /d to loop through the directories.
Modified batch file:
@echo off
xcopy /s \\some_server\MYFOLDER1 c:\MYFOLDER1\
xcopy /s \\some_server\MYFOLDER2 c:\MYFOLDER2\
for /d %%x in (C:\MYFOLDER1 c:\MYFOLDER2) do (
ren "%%x\*.nary" *.
)
pause
c:\?Test if the folder already exists before running the xcopy:
Modified batch file:
@echo off
if not exist C:\MYFOLDER1 echo xcopy /s \\some_server\MYFOLDER1 c:\MYFOLDER1\
if not exist C:\MYFOLDER2 echo xcopy /s \\some_server\MYFOLDER2 c:\MYFOLDER2\
for /d %%x in (C:\MYFOLDER1 c:\MYFOLDER2) do (
ren "%%x\*.nary" *.
)
pause
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With