Author: William Gerbert
Convert from UNC notation to Drive letter?
Answer:
The function ExpandUNCFileName function converts a mapped path/file to UNC, but how
can this process be reversed?
There is no simple function that would do the trick, you have to go through all
existing 'remote' drives, look at their UNC name and compare them with the one you
are interested in:
1 program P;
2 3 procedure TForm1.Button1Click(Sender: TObject);
4 const5 YOURUNCFILENAME = '\\ISS\VOL1\ISS\SHARE\';
6 var7 Drive: Char;
8 Drlist: TStringList;
9 Filist: TStringList;
10 I: integer;
11 begin12 Drlist := TStringList.Create;
13 Filist := TStringList.Create;
14 for Drive := 'a' to 'z' do15 case GetDriveType(PChar(Drive + ':\')) of16 DRIVE_REMOTE:
17 begin18 Filist.Add(expanduncfilename(Drive + ':\'));
19 Drlist.Add(Drive)
20 end21 end;
22 {......}23 I := Filist.indexof(YOURUNCFILENAME);
24 if I > -1 then25 ShowMessage(YOURUNCFILENAME + 'Mapped to drive ' + Drlist[I]);
26 27 Drlist.Free;
28 Filist.Free
29 end;
30 31 end.