delphi 絕對路徑的處理

獲取應用程序的當前路徑已經衆所周知,此處不再多做說明了。現在自己寫了一個把相對路徑和絕對路徑轉換的函數 ,如下

function ExtractRelativePath(const Path, AFile: string): string;
var
  SLen: Integer;
  i, j: Integer;
  LString: string;
  SubStr: string;
  PointCount: Integer;


begin
  SLen := Length(AFile);
  for i:=0 to SLen-1 do
  begin
    if (AFile[i] = '/') or (AFile[i] = '\') then Break;
  end;
  SubStr := Copy(AFile,i,SLen);
  PointCount := i-1;
  i := Length(Path);
   while (i>2) and (PointCount>0) do
   begin
     if (Path[i] = '/') or (Path[i] = '\') then Dec(PointCount);
     Dec(i);
   end;
   LString := Copy(Path,1,i);
   Result :=  LString + SubStr;
end;


  說明:      轉換相對路徑成絕對路徑

例如:
  ExtractRelativePath('E:\work\0716yunPad\PadClient\exe\exe\exe\','...\roomlist.xml')
  返回   E:\work\0716yunPad\PadClient\exe\roomlist.xml


發佈了24 篇原創文章 · 獲贊 23 · 訪問量 9萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章