简体   繁体   English

构建事件:复制文件夹,除了一个文件

[英]Build events: copy folder except one file

In build events I need to copy the whole folder except one specific file.在构建事件中,我需要复制除一个特定文件之外的整个文件夹。 Is it possible?可能吗?

XCopy supports an /Exclude flag that will do what you want. XCopy支持/Exclude标志,它会做你想做的事。

From help xcopy :help 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.例如,指定像 \obj\ 或 .obj 这样的字符串将分别排除目录 obj 下的所有文件或所有具有 .obj 扩展名的文件。

So, you'll make a file that contains a list of files to be excluded (one per line), and specify the exclusion file on your xcopy command line.因此,您将创建一个包含要排除的文件列表(每行一个)的文件,并在 xcopy 命令行上指定排除文件。

Robocopy also has file exclusion support. Robocopy还具有文件排除支持。

From robocopy /?robocopy /? :

/XF file [file]...

eXclude Files matching given names/paths/wildcards.排除与给定名称/路径/通配符匹配的文件。

This doesn't require an extra exclusion file.这不需要额外的排除文件。 You specify a pattern, instead.相反,您指定一个模式。

This can be done in three easy steps:这可以通过三个简单的步骤完成:

  1. Create a file, ie exclude.txt创建一个文件,即exclude.txt
  2. Add the filenames that you want to exclude添加要排除的文件名
  3. Use the following command: xcopy source target /exclude:exclude.txt使用以下命令: xcopy source target /exclude:exclude.txt

You can keep exclude.txt in source control.您可以将 exclude.txt 保留在源代码管理中。

Tip: if the target is a directory, append it with \* , then xcopy understands it's a directory and not a file.提示:如果目标是一个目录,append 它带有\* ,那么xcopy理解它是一个目录而不是一个文件。

do it in 2 steps,分两步完成,

1st copy the entire folder to the new location 1st将整个文件夹复制到新位置

2nd delete the file from the newly created folder 2nd从新创建的文件夹中删除文件

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

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