Forum > Unix
list Windows drive Letters (compile on Linux)
bjlockie1:
I am writing a file manager type app on Linux that also needs to run on Windows.
It is ok on Linux but I don't account for drive letters on Windows.
Is there a way to list available drive letters (instead of hard coding A: to Z:)?
I am using ChDir, is that going to change the drive?
Leledumbo:
Guess you have to ifdef since drive letters is a Windows only concept. Windows API has GetLogicalDrives function that you can call, it will return a single LongWord / DWord value whose bits indicate whether the corresponding drive letter is assigned or not, i.e. bit 0 = drive A, bit 1 = drive B and so on.
Bart:
Maybe take a look at TShellTreeView and see how the root node is populated?
Bart
Aidex:
And if it is of interest what type each drive is, I recommend Windows.GetDriveType()
https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getdrivetypea
Remy Lebeau:
--- Quote from: Leledumbo on November 19, 2020, 10:45:58 pm ---Windows API has GetLogicalDrives function that you can call, it will return a single LongWord / DWord value whose bits indicate whether the corresponding drive letter is assigned or not
--- End quote ---
The API also has a GetLogicalDriveStrings() function, which returns each assigned drive letter in a '<letter>:\' string format, which can be passed as-is to any API that takes a drive root as input, including GetDriveType().
Navigation
[0] Message Index
[#] Next page