XCOPY / Исключить синтаксис каталога

20336
Onion-Knight

Я пытаюсь использовать XCOPYдля копирования каталог, который выглядит следующим образом:

-MainFolder -ManyFoldersIWantToCopy -ManyFoldersIWantToCopy -... -Source Code 

Я хочу использовать /EXCLUDEопцию для копирования всех папок, кроме Source Code.

Я попытался использовать следующее, но мне не повезло:

xcopy "Source" "Destination" /EXCLUDE:"\Source Code\" /E /C /R /I /K /Y

Сообщение об ошибке я получаю говорит: Can't read file: "\Source Code\".

Я попытался удалить все двойные кавычки, используя вместо них одинарные кавычки, с / без, но я получаю то же сообщение об ошибке.

Есть идеи?

4

3 ответа на вопрос

6
Hugh Allen
C:\>xcopy /? ... /EXCLUDE:file1[+file2][+file3]... Specifies a list of files containing strings. Each string should be in a separate line in the files. When any of the strings match any part of the absolute path of the file to be copied, that file will be excluded from being copied. For example, specifying a string like \obj\ or .obj will exclude all files underneath the directory obj or all files with the .obj extension respectively. 

Вам нужно поместить «Исходный код» в файл и указать этот файл в командной строке.

Нужно ли включать кавычки вокруг исходного кода в файл исключения, или он может обрабатывать пробелы в порядке? dunxd 12 лет назад 0
2
Ken Richards

I believe this error needs some further explanation. I found this blog post on the issue very informative.

Basically, you need to use the old 8.3 (DOS short filenames in the exclude path). You can determine the short names by running the command "DIR /X" from a command prompt after changing directory to the parent of the folder (you want the 8.3 name for). It's a shame MS hasn't updated this command to support long file names.

I would suggest using robocopy instead if you don't want to use short path/file names. Of course I guess you could put the long names in an external "excluded_files.txt". This does seem to be supported by XCopy.

0
Chris

I used the xcopy EXCLUDE flag successfully without putting the lines in quote marks, even though many of the paths contained spaces. So for me (Win7 Home Premium SP1 repair install DOS prompt) the carriage returns were adequate delimitation. I just used a plain text file in the format:

file 1.txt path 2\file 2.text and so on\and so forth.txt 

then EXCLUDE:F:\filename.txt as the xcopy flag. I didn't include the drive letter in the lines in the exclude file (as confirmed in the /? page it only needs a partial match). It skipped the files named very quickly. I combined this with /D:09-21-2014 to only get recent files and a host of other tags successfully.

To confirm, I did not use the old DOS short names, contrary to Ken Richard's finding above.