获取应用程序的当前路径已经众所周知,此处不再多做说明了。现在自己写了一个把相对路径和绝对路径转换的函数 ,如下
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