Xcopy Command excluding files and folders [duplicate]
Asked Answered
T

3

29

I want to copy files and folders in a directory to another folder excluding a list of files and folders.Is that possible.

I was just trying to copy excluding file :

 xcopy c:\t1 c:\t2 /EXCLUDE:exclusion.txt

But it keeps saying read cant read file : exclusion.txt

Can anyone help me on this?

Thanks

Trocki answered 10/9, 2012 at 17:28 Comment(1)
try copy /? and read the portion titled /EXCLUDE:file1[+file2][+file3]...Weisshorn
C
27

Just give full path to exclusion file: eg..

-- no - - - - -xcopy c:\t1 c:\t2 /EXCLUDE:list-of-excluded-files.txt

correct - - - xcopy c:\t1 c:\t2 /EXCLUDE:C:\list-of-excluded-files.txt

In this example the file would be located " C:\list-of-excluded-files.txt "

or...

correct - - - xcopy c:\t1 c:\t2 /EXCLUDE:C:\mybatch\list-of-excluded-files.txt

In this example the file would be located " C:\mybatch\list-of-excluded-files.txt "

Full path fixes syntax error.

Chemisette answered 30/1, 2014 at 4:32 Comment(0)
W
18

Like Andrew said /exclude parameter of xcopy should be existing file that has list of excludes.

Documentation of xcopy says:

Using /exclude

List each string in a separate line in each file. If any of the listed strings match any part of the absolute path of the file to be copied, that file is then excluded from the copying process. For example, if you specify the string "\Obj\", you exclude all files underneath the Obj directory. If you specify the string ".obj", you exclude all files with the .obj extension.

Example:

xcopy c:\t1 c:\t2 /EXCLUDE:list-of-excluded-files.txt

and list-of-excluded-files.txt should exist in current folder (otherwise pass full path), with listing of files/folders to exclude - one file/folder per line. In your case that would be:

exclusion.txt
Winou answered 19/6, 2013 at 15:45 Comment(0)
S
13

It is same as above answers, but is simple in steps

c:\SRC\folder1

c:\SRC\folder2

c:\SRC\folder3

c:\SRC\folder4

to copy all above folders to c:\DST\ except folder1 and folder2.

Step1: create a file c:\list.txt with below content, one folder name per one line

folder1\

folder2\

Step2: Go to command pompt and run as below xcopy c:\SRC*.* c:\DST*.* /EXCLUDE:c:\list.txt

Seddon answered 14/11, 2013 at 22:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.