3

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-

Farooq Zaman
  • 495
  • 1
  • 6
  • 21

1 Answers1

10

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.

Adrian McCarthy
  • 45,555
  • 16
  • 123
  • 175
David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490