原样复制过来,notCopy这里表示不复制的目录
@echo off
set "notCopy=目录1,目录2,目录3"
set src=D:\Data
set dest=D:\Data2
cd /d %src%
for /f "tokens=*" %%i in ('dir /B %src%') do (
echo %notCopy%|findstr "%%i">nul||(echo %%~ai|findstr "d">nul && xcopy %%~fi\* %dest%\%%~ni\ /E /Y || xcopy %%~fi %dest%\ /S /Y)
)
-----&& ping 127.0.0.1 -n 3 > nul 或者 && timeout 3 > NUL(它适用于 Win 7,但不适用于 Win XP) ---表示停顿3秒
@echo off
set src=D:\PDData\8月测量数据\8-1白
set dest=D:\PDtest
cd /d %src% && for /r %%i in (*) do (
echo %%i|findstr ".xls .xlsx" && xcopy /d "%%~fi" %dest%\ /S /Y && ping 127.0.0.1 -n 3 > nul
)
net use W: /delete /Y
pause
把所有文件放到一个文件目录下
@echo off
set src=D:\smt
set dest=D:\smt2
cd /d %src%
xcopy *.* %dest%\
for /f "tokens=*" %%i in ('dir /B %src%') do (
echo %notCopy%|findstr "%%i">nul||(echo %%~ai|findstr "d">nul && xcopy %%~fi %dest%\ /S /Y)
)
网络路径下的一个文件夹下的所有文件放到一个文件目录下
@echo off
net use W: /delete
net use W: "\\192.186.1.1\Security\ADE" "P@ssw0rd" /user:"*.AD\ITteam" /persistent:yes
set src=W:\
set dest=D:\smt2
cd /d %src% && for /r %%i in (*) do (
echo %%i|findstr ".xls .xlsx" && xcopy "%%~fi" %dest%\ /S /Y
)
net use W: /delete /Y
网络路径下所有文件和文件夹原样复制
@echo on
net use W: /delete
net use W: "\\*.201.20.1\Security\ADE" "ItP@ssw0rd" /user:"*.AD\ITteam" /persistent:yes
set src=W:\
set dest=D:\smt2
cd /d %src%
for /f "tokens=*" %%i in ('dir /B %src%') do (
echo %notCopy%|findstr "%%i">nul||(echo %%~ai|findstr "d">nul && xcopy %%~fi\* /d %dest%\%%~ni\ /E /Y || xcopy %%~fi /d %dest%\ /S /Y)
)
net use W: /delete /Y
pause