如何检查驱动器是否有效

问题描述:

嗨.

我正在尝试找到一种方法来检查硬盘上的驱动器是否有效.例如:如果我将网络驱动器命名为T:是否有API可用于检查T:是否有效(也许网络已关闭?).

我对此表示感谢或帮助.

谢谢.

Stan the man

Hi.

I am trying to find a way to check whether a drive is valid on the hard disk. Ex: if I name a network drive to T: is there an API I can use to check that T: is valid (maybe the network is down?).

I would appreciate any hint or help on this.

Thanks.

Stan the man

^ ]
http://*.com/questions/10094222/how-do-i-check-if-a-visual-c-argument-is-a-valid-drive-letter [ http://www. developer.nokia.com/Community/Discussion/showthread.php?105939-check-out-if-the-drive-exists-or-not [ http://www.tgmdev.be/getdiskdata.htm [
http://msdn.microsoft.com/en-us/library/system.io.directory.exists.aspx#Y0[^]
http://*.com/questions/10094222/how-do-i-check-if-a-visual-c-argument-is-a-valid-drive-letter[^]
http://www.developer.nokia.com/Community/Discussion/showthread.php?105939-check-out-if-the-drive-exists-or-not[^]
http://www.tgmdev.be/getdiskdata.htm[^]


hi 我不知道api,但是您可以使用CFile进行此操作.
将一个空文件保存到驱动器,如果成功,它将返回1,否则返回0

hi I don''t know the api but you can do this with CFile.
save an empty file to the drive, if it success it will returns 1 else it returns 0

CFile f;
if(f.Open(drive_path+_T("\\\\a.txt"),CFile::modeCreate|CFile::modewrite)){
   f.Close();
   //drive_path is valid drive
}else{
   //drive_path isnot valid
}