Delphi - convert physical path (device File handle) to virtual path
delphi, path, virtual
Solution
Personally I prefer the native way:
function GetHDDDevicesWithDOSPath:TStringlist;
var
i: integer;
root: string;
device: string;
buffer: string;
begin
setlength(buffer, 1000);
result:=TStringlist.create;
for i := Ord('c') to Ord('z') do
begin
root := Char(i) + ':';
if (QueryDosDevice(PChar(root), pchar(buffer), 1000) <> 0) then
begin
device := pchar(buffer);
result.add(format('%s = %s\',[device, root ]));
end;
end;
end;
NB: This code sample is taken from: http://www.delphipraxis.net/165249-auflistung-devices.html
This will return a map between logical drive and path. In my case:
\Device\HarddiskVolume2 = c:\
\Device\HarddiskVolume3 = d:\
\Device\IsoCdRom0 = e:\
\Device\CdRom0 = f:\
\Device\hgfs\;Z:0000000000084af9\vmware-host\Shared Folders = z:\
You have to replace "\device\harddisk" part in your path with coresponding drive letter.
Please, note drive letters are user dependent. Some useful links:
- Defining an MS-DOS Device Name
- Naming Files, Paths, and Namespaces
- coverting physical drive to logical drive how to?
Problem
How can I convert a path like \Device\HarddiskVolume3\Windows into its corresponding virtual path? (like c:\Windows in this case)