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