VS PostBuild Event - Copy file if it exists

Brad Leach picture Brad Leach · Jul 10, 2012 · Viewed 20.3k times · Source

Is there a simple way to copy a file in a post-build event for a Visual Studio project, but only if the file exists? (i.e. don't fail the build if the file doesn't exist)

I've tried some options using xcopy. But I feel so stupid - I can't seem to get my head around what switches I might need with xcopy.

Answer

Hailton picture Hailton · Jul 10, 2012

Use "IF" command:

IF EXIST file.txt xcopy file.txt [destination_folder]\ /Y