Search code examples
c++windowsdrive

How do I check if a Visual C++ argument is a valid drive letter?


Like the title says, I have a C++ program and the user passes in an argument. I want to validate whether the argument passed is a valid DOS/Windows drive letter (i.e. C:. D:. E:) and that the drive exists on the system. How do I do this?


Solution

  • You can get the type of a drive with GetDriveType() - which also tells you if a drive doesn't exist or isn't availble

    Or the 'correct' way is to enumerate through all the drives