SiberianGuy
SiberianGuy

Reputation: 25312

Build events: copy folder except one file

In build events I need to copy the whole folder except one specific file. Is it possible?

Upvotes: 2

Views: 845

Answers (3)

Merlyn Morgan-Graham
Merlyn Morgan-Graham

Reputation: 59151

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.

Upvotes: 4

Abel
Abel

Reputation: 57189

This can be done in three easy steps:

  1. Create a file, i.e. 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.

Upvotes: 2

Jason
Jason

Reputation: 15931

do it in 2 steps,

1st copy the entire folder to the new location

2nd delete the file from the newly created folder

Upvotes: 1

Related Questions