Exclude folders in batch-copy-script

偶尔善良 提交于 2019-12-12 07:34:23

问题


I am using a batch file on a USB stick to backup my pictures. I use the following command:

for /r C:\ %%x in (*.jpg *.png *.gif) do @copy /y %%x .

I want to exclude files in the mailfolder WINDOWS and PROGRAM FILES.

Does anyone have an idea how I can do this with a batch file?


回答1:


Drop COPY and use ROBOCOPY which exists in Windows Vista+ & is downloadable for prior versions.

It supports /XD to exclude specific directories & /XF to exclude file masks at the command line.

E.g.

robocopy.exe c:\ c:\destination\ *.jpg *.png *.gif /xd "Program files" "windows" /S

(Note this will recreate the directory structure in c:\destination\, which thinking about it may not be what you want)




回答2:


Turn copy into xcopy and then you can use it's /EXCLUDE switch

@xcopy %%x /y /EXCLUDE:\WINDOWS\

See xcopy /? for the details.



来源:https://stackoverflow.com/questions/12976848/exclude-folders-in-batch-copy-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!