简体   繁体   中英

How to test if a folder exists in a post build event?

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.

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

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

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