Home > Back-end >  How to test if a folder exists in a post build event?
How to test if a folder exists in a post build event?

Time:05-05

In a database project in Visual Studio 2022, I would like to copy files only if the target folder exists. Assume the target folder is called c:\files

I did something like:

if exist "c:\files\"
xcopy /Y  $(ProjectDir)$(OutputPath)$(TargetDatabase).dacpac c:\files

but the 'if exist' line gives an error "...... exited with code 255.". I am not sure 'if exist' is even correct. The xcopy line copies fine without the if statement.

CodePudding user response:

The if exist is fine, just the whitespace syntax seems problematic it should work if you it all on one line or use brackets like this:

if exist "c:\files\" (
xcopy /Y  $(ProjectDir)$(OutputPath)$(TargetDatabase).dacpac c:\files
)
  • Related