nt路径转dos windows路径

// \??\C:\WINDOWS\system32\drivers
//选择的盘是映射盘,需要得出正确的路径
function GetDosPath(path:string):string;
var
 DriveChar, Drive: string;
 Buf: Array [0..MAX_PATH] of Char;
 BufferSize: DWORD;
 pathList:TStringList;
begin
 Result := path;
 if Length(path) < 3 then
  Exit;
 DriveChar := Copy(path,1,2);
 BufferSize := QueryDosDevice(PAnsiChar(DriveChar), Buf, MAX_PATH);
 if BufferSize > 0 then
 begin
  //-2有两个#0 结尾
  SetString(Drive, Buf, BufferSize-2);
  try
   pathList :=  TStringList.Create;
   pathList.Delimiter := '\';
   pathList.DelimitedText := Drive;
   if pathList.Count > 0 then
    if pathList[1] ='Device' then //物理硬盘 \Device\HarddiskVolume1\x86.sys
      Exit
    else
    begin
     pathList.Delete(0);
     if pathList.Count >0 then
      pathList.Delete(0);
     Result := pathList.DelimitedText+Copy(path,3,Length(path)-2);
    end;
  finally
   pathList.Free;
  end;
 end;
end;

 

posted @ 2022-01-16 21:41  Tag  阅读(135)  评论(0编辑  收藏  举报