was ist neu ¦  programmier tips ¦  indy artikel ¦  intraweb artikel ¦  informationen ¦  links ¦  interviews
 sonstiges ¦  tutorials ¦  Add&Win Gewinnspiel

Tips (1541)

Dateien (137)
Datenbanken (90)
Drucken (35)
Grafik (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Mathematik (76)
Multimedia (45)
Oberfläche (107)
Objekte/
ActiveX (51)

OpenTools API (3)
Sonstiges (126)
Strings (83)
System (266)
VCL (242)

Tips sortiert nach
Komponente


Tip suchen

Tip hinzufügen

Add&Win Gewinnspiel

Werbung

46 Visitors Online


 
...PathCombine & ExtractRelativePath verwenden?
Autor: Ken Revak
[ Tip ausdrucken ]  

Tip Bewertung (7):  
     


{
Question:

Could anyone point me to any function that can receive
an HTML style relative path as its input and return a full path as its
output based on the exe's current location, e.g

Input: '..\..\test2.dat'
Output: C:\folder1\test2.dat

(assuming that the executable is running from
 C:\folder1\folder2\folder3\Project1.exe)

}

{

Answer:

PathCombine() Concatenates two strings that represent properly
formed paths into one path, as well as any relative path pieces.
}

function PathCombine(lpszDest: PChar; const lpszDir, lpszFile: PChar):
PChar; stdcallexternal 'shlwapi.dll' name 'PathCombineA';
function PathCombineA(lpszDest: PAnsiChar; const lpszDir, lpszFile:
PAnsiChar): PAnsiChar; stdcallexternal 'shlwapi.dll';
function PathCombineW(lpszDest: PWideChar; const lpszDir, lpszFile:
PWideChar): PWideChar; stdcallexternal 'shlwapi.dll';

{
 Requires Windows 2000 (or Windows NT 4.0 with Internet Explorer 4.0 or later);
 Requires Windows 98 (or Windows 95 with Internet Explorer 4.0 or later)
}

procedure TForm1.FormCreate(Sender: TObject);
var
  
dest: string;
  BaseFile, RelativePath: String;
begin
  
BaseFile := 'C:\folder1\folder2\folder3\';
  RelativePath := '..\..\test2.dat';
  SetLength(dest, MAX_PATH);
  PathCombine(@dest[1], PChar(ExtractFilePath(BaseFile)), PChar(RelativePath));
  SetLength(dest, StrLen(@Dest[1]));
  ShowMessage(dest);
end;

{
  The ExtractRelativePath function takes a base directory but the
  ExpandFilename function does the expansion based on the current
  directory not a given base path.
}

RelativePath := ExtractRelativePath(ExtractFilePath(BaseFile), TargetFile);


 

Bewerten Sie diesen Tipp:

dürftig
ausgezeichnet


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners