简体   繁体   中英

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.

From 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.

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.

Robocopy also has file exclusion support.

From 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
  2. Add the filenames that you want to exclude
  3. Use the following command: xcopy source target /exclude:exclude.txt

You can keep exclude.txt in source control.

Tip: if the target is a directory, append it with \* , then xcopy understands it's a directory and not a file.

do it in 2 steps,

1st copy the entire folder to the new location

2nd delete the file from the newly created folder

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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