简体   繁体   English

XCOPY - 如何排除某个文件名?

[英]XCOPY - How to exclude a certain file name?

This is my current xcopy command:这是我当前的 xcopy 命令:

xcopy C:\SourceCodeOld\Release\"Source Code"\*.vb C:\SourceCodeNew\"Source Code"\ /S /Y /R

In several subfolders, I have a file named "AssemblyInfo.vb".几个子文件夹中,我有一个名为“AssemblyInfo.vb”的文件。 How can I exclude it from being copied?我怎样才能排除它被复制?

There is an /EXCLUDE option of xcopy , which allows to specify (the path to) a text file that contains partial file paths/names one per line (note also the fixed quotation): xcopy有一个/EXCLUDE选项,它允许指定(路径)一个包含部分文件路径/名称的文本文件,每行一个(另请注意固定引号):

xcopy /S /Y /R /I /EXCLUDE:exclude.txt "C:\SourceCodeOld\Release\Source Code\*.vb" "C:\SourceCodeNew\Source Code"

with exclude.txt being in the current working directory and containing: exclude.txt位于当前工作目录中并包含:

AssemblyInfo.vb

However, the implementation of the /EXCLUDE option is terrible, because actually all files are excluded whose absolute source paths contain any of the given strings at any position (in a case-insensitive manner).但是, /EXCLUDE选项的实现很糟糕,因为实际上所有文件都被排除在外,其绝对源路径包含任何position 处的任何给定字符串(以不区分大小写的方式)。 Moreover, you cannot even use wildcards in these strings.此外,您甚至不能在这些字符串中使用通配符 Furthermore, you cannot provide a quoted path to the exclusion text file to protect potential spaces or special characters.此外,您不能为排除文本文件提供带引号的路径来保护潜在的空格或特殊字符。 (Refer also to this related answer of mine .) (另请参阅我的this related answer 。)


I strongly recommend to use the robocopy command , whose exclusion options are more mature:强烈推荐使用robocopy命令,它的排除选项比较成熟:

robocopy "C:\SourceCodeOld\Release\Source Code" "C:\SourceCodeNew\Source Code" "*.vb" /S /XF "AssemblyInfo.vb"

This truly excludes only files whose names are AssemblyInfo.vb .这实际上只排除了名称为AssemblyInfo.vb的文件。

Create a file excludes.txt and add the files to exclude to it (each in a new line)创建一个文件excludes.txt并将要排除的文件添加到其中(每个都在一个新行中)

AssemblyInfo.vb
anotherfile.vb

Then run your xcopy command using the /EXCLUDE parameter pointing to the file that contains the files to exclude:然后使用指向包含要排除的文件的文件的/EXCLUDE参数运行xcopy命令:

xcopy "C:\SourceCodeOld\Release\Source Code\*.vb" "C:\SourceCodeNew\Source Code\" /EXCLUDE:excludes.txt /S /Y /R

To see the various options available for the /EXCLUDE parameter, run xcopy /?要查看可用于/EXCLUDE参数的各种选项,请运行xcopy /?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM