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?
Just have a look at when the files where last accessed by right clicking on the files you want to see if they are accessed and select properties. It will show the last access date (when the file was last opened), Last modified date (when the file was last saved).
You can check whether certain files are present using an 'IF EXIST' command. You can use this to execute commands via a batch file. If any spaces are present in the path name, you must place the entire path+filename+extension between straight double quotes.
If you haven't already, connect the flash drive to the computer, or insert the memory card in the memory card slot or reader. After a few seconds, a window should open showing the new drive and its contents (A). If a new window doesn't pop up, you can access the drive by pressing Windows key + E to open File Explorer.
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:\
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With