function GetAbsolutePathEx(BasePath, RelativePath:string):string; var Dest:array [0..MAX_PATH] of char; begin FillChar(Dest,MAX_PATH+1,0); PathCombine(Dest,PChar(BasePath), PChar(RelativePath)); Result:=string(Dest); end;
示范:
S := GetAbsolutePath('C:\Windows\System32', '..\DEMO.TXT')
// S 将得到 'C:\Windows\DEMO.TXT
//绝对路径转换为相对路径的函数
function GetRelativePath(const Path, AFile: string): string;
function GetAttr(IsDir: Boolean): DWORD; begin if IsDir then Result := FILE_ATTRIBUTE_DIRECTORY else Result := FILE_ATTRIBUTE_NORMAL; end;
var p: array[0..MAX_PATH] of Char; begin PathRelativePathTo(p, PChar(Path), GetAttr(False), PChar(AFile), GetAttr(True)); Result := StrPas(p); end;