Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude folders in batch-copy-script

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?

like image 307
user1759708 Avatar asked Oct 19 '12 14:10

user1759708


2 Answers

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)

like image 144
Alex K. Avatar answered Sep 29 '22 20:09

Alex K.


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

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

See xcopy /? for the details.

like image 25
Bali C Avatar answered Sep 29 '22 19:09

Bali C