I have batch files with the construct:
if exist F:\ copy /y Application.exe F:\
at the end of a compile, to copy the executable to a USB key if it is plugged in. It has worked fine with USB keys but when I had a USB multi card reader plugged in (this looks like drives E:..H:, and if there is no SD card plugged in, when I execute the above batch line, I get a "Windows - no disk" snag message.
If there is a card plugged in, I don't get the message, (and the file is copied), if the card reader is not plugged in, I don't get the message and the file is not copied (obviously), but in neither of these cases does the batch file stop running. It's only if the card reader is plugged in but there is no card in the drive.
Can I check quietly for no "disk" in these USB drives from a batch file?
Replace IF EXIST
with DIR
and use the &&
or ||
depending on what you want to happen.
For example,
To replace IF EXIST...
DIR F:\ && copy /y Application.exe F:\
To replace IF NOT EXIST
DIR F:\ || copy /y Application.exe F:\
If You want to suppress the STDOUT and STDERR of the DIR to mimic the IF EXIST exactly...
To replace IF EXIST...
DIR F:\ 1>NUL 2>&1 && copy /y Application.exe F:\
To replace IF NOT EXIST
DIR F:\ 1>NUL 2>&1 || copy /y Application.exe F:\