Data Access Worldwide Knowledge Base

Article ID 2246
Article Title HOWTO: Discover the drive type
Article URL http://www.dataaccess.com/kbasepublic/KBPrint.asp?ArticleID=2246
KBase Category VDF (GENERAL)
Date Created 09/29/2006
Last Edit Date 10/04/2006


Article Text
QUESTION:
Assume that I have a drive letter. How do I get information about that drive? I want to know if it is a hard-disk, a CD-ROM or a floppy disk.

ANSWER:
There is a Windows API call called GetDriveType that you can use. You pass it the root name of your drive and it returns an enumerated constant indicating the drive type.

Define DRIVE_UNKNOWN     For 0
Define DRIVE_NO_ROOT_DIR For 1
Define DRIVE_REMOVABLE   For 2
Define DRIVE_FIXED       For 3
Define DRIVE_REMOTE      For 4
Define DRIVE_CDROM       For 5
Define DRIVE_RAMDISK     For 6

External_Function WinAPI_GetDriveType "GetDriveTypeA" Kernel32.Dll Pointer lpRootPathName Returns Integer

Function GetDriveType Desktop String sRootPathName Returns String
    Integer iRetval

    Move (WinAPI_GetDriveType (AddressOf (sRootPathName))) To iRetval
  
    Function_Return iRetval
End_Function // GetDriveType

You can call this as follows:

Get GetDriveType "C:\" To iDriveType


Contributed By:
Vincent Oorsprong
Company: Data Access Worldwide
email: vincent.oorsprong@dataaccess.eu
Web Site: http://www.dataaccess.eu

Web Links Related to this Article
MSDN Documentation
URL=http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/getdrivetype.asp


Email this Article
Email this Article to a Colleague
Send Feedback on this Article to Data Access Worldwide
Copyright ©2010 Data Access Corporation. All rights reserved.

The information provided in the Data Access Technical Knowledge Base is provided "as is" without warranty of any kind. Data Access Corporation disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. In no event shall Data Access Corporation or its suppliers be liable for any damages whatsoever including direct, indirect, incidental, consequential, loss of business profits or special damages, even if Data Access Corporation or its suppliers have been advised of the possibility of such damages. Some states do not allow the exclusion or limitation of liability for consequential or incidental damages so the foregoing limitation may not apply.