I need to write a batch file to copy a folder, not file, from a network drive, that has been the most recently updated, to my local machine.
This is what I have, but it cannot find anything to copy because I want to copy a folder, not a file.
for /f "delims=" %%a in ('dir S:\Development\NightlyBuilds /B /A-D /O-D') do copy "%%a" U:\PWJ
答案 0 :(得分:0)
您可以使用copy
而不是xcopy
。使用/s
标志递归复制。确保使用\
终止PWJ文件夹,以指示目标是文件夹。您也可以使用robocopy。它更加强大。您可以在robocopy /?
。
答案 1 :(得分:0)
您使用了错误的FOR和DIR命令选项,为最新到最旧的日期中的每个文件执行复制。
@ECHO OFF
(SET SrcDir=S:\Development\NightlyBuilds)
(SET DstDir=U:\PWJ)
IF NOT EXIST "%SrcDir%\" EXIT/B
IF NOT EXIST "U:\PWJ\" EXIT/B
IF /I NOT "%CD%"=="%SrcDir%" PushD "%SrcDir%"
FOR /F "DELIMS=" %%A IN ('DIR/B/AD-L/OD *') DO SET Latest="%%A"
ROBOCOPY %Latest% "%DstDir%\%Latest%" /E
EXIT/B