How can I detect if there is a floppy in a drive?

前端 未结 7 1787
孤独总比滥情好
孤独总比滥情好 2021-01-18 23:03

I tried to use DriveInfo.IsReady, but it returns false if an unformatted floppy is in the drive.

7条回答
  •  心在旅途
    2021-01-18 23:18

    You can always try to read a sector from the floppy and see if it succeeds or not.

    I have no clue how to do it in .NET, but here is the C/C++ equivalent.

    SetLastError(0);
    HANDLE h = CreateFile("\\\\.\\A:", ...);
    if (!ReadFile(h, buf, 512, &bytes_read, 0))
    {
      DWORD err = GetLastError();
    }
    

    CreateFile, ReadFile

提交回复
热议问题