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
//绝对路径转换为相对路径的函数 需要引用 ShlwApi.pas
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;
示范:
S := GetAbsolutePath('C:\Windows\System32', 'C:\Windows\System32\DEMO.TXT')
// S 将得到 .\DEMO.TXT
系统环境变量
得到系统当前所有的环境变量
procedure TForm1.Button1Click(Sender: TObject);
var
p, p1 : PChar;
begin
Memo1.Lines.Clear;
Memo1.WordWrap := false;
{$IFDEF WIN32}
p := GetEnvironmentStrings;
p1 := p;
{$ELSE}
p := GetDOSEnvironment;
{$ENDIF}
while p^ <> #0 do begin
Memo1.Lines.Add(StrPas(p));
Inc(p, lstrlen(p) + 1);
end;