本文整理自网络,侵删。
需要引用 ShlwApi.pas
//取绝对路径的函数
// BasePath: 是参考路径。RelativePath: 是指相对路径
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;
相关阅读 >>
Delphi d10.x 并行库ppl编程之 tparallel.for
Delphi xe增强的rtti妙用--动态创建包中的窗口类
Delphi firemonkey处理图形的方式与vcl处理图形的方式大不相同
Delphi 泛型 tdictionary<string,string>
更多相关阅读请进入《Delphi》频道 >>