Question

FindFirstFile function is causing "There is no disc in the drive. Please insert a disc into drive" Error. The cause of this error is that there is no sd-card in the USB stick and it's empty. My problem is that I have to scan all the drives for a specific directory and I cannot distinguish whether the drive is empty or not. How can I do this?

I am developing application for Windows and I am using MFC for development.

Any help would be highly appreciated.

Farooq-

Was it helpful?

Solution

I'm guessing a little, but I suspect you need to call SetErrorMode() passing the SEM_FAILCRITICALERRORS flag to suppress this dialog appearing. Instead FindFirstFile() will return a failure code and you can move on to the next drive in the enumeration.

Edit: For Windows 7 and up, consider SetThreadErrorMode() instead. That limits the effect of the mode. Also remember to restore the original mode as soon as possible.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top