Visual-studio – VS PostBuild Event – Copy file if it exists

post-build-eventvisual studio

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.

Best Answer

Use "IF" command:

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