What are the standard tasks to complete & lt; - & gt; Relative path conversion in Delphi?
For example:
- The 'base' path is
'C: \ Projects \ Project1 \'
- relative The path is
. \ Share \ somefile.pas'
- Absolute Path is
'C: \ projects \ shared \ somefile.pas'
I'm looking for something like this:
Function AbsToRel (const espath, basepath: string): string; // '.. ... shared \ somefile.pas' = // AbsToRel ('C: \ Projects \ shared \ somefile.pas', 'C: \ Projects \ Project1 \') function RelToAbs (Constant RelPath, BasePath: String): string; // 'C: \ Projects \ shared \ somefile.pas' = // RelToAbs ('... \ share \ somefile.pas', 'C: \ Projects \ Project1 \') < / Div>
I will use the second function as the second and in the latter case, in the form of logic you will be the string of the base path and the relative path Pass the amount.
Function PathRelativePathTo (pszPath: PChar; pszFrom: PCR; dwAttrFrom: DWORD; pszTo: PChar; DwAtrTo: DWORD): LongBool; Stdcall; External 'shlopi Dll 'name' Pethralvethathpathu '; Work AbsToRel (Constant Espath, Basapath: String): String; Var Path: Sir's [0..MAX_PATH-1] array; Start PathRelativePathTo (@ path [0], PCHAR (basepath), FILE_ATTRIBUTE_DIRECTORY, PCHAR (espath), 0); Results: = Path; End; Function PathConnicalise (LPSZTST: PCAR; LPSASRC: PCHR): Longbull; Stdcall; External 'shlopi Dll 'name' PathankonicalKW '; RelToAbs function (constant relaypath, base path: string): string; Var DST: Sir's [0..MAX_PATH-1] Sir; Start the PathCononicalize (@DST [0], PCHara (Training Boxesite + RileyPath); Results: = DST; Finished; Process TForm4.FormCreate (Sender: TObject); Start ShowMessage (AbsToRel ('C: \ Users \ Andreas Rejbrand \ Desktop \ file.txt ',' C: \ Users \ Andreas Rejbrand \ Pictures')); ShowMessage (RelToAbs ('.. \ Video \ Movie. Wma', 'C: \ Users \ Andreas Rejbrand \ Desktop' Of course, if you use the non-Unicode version of Delphi (that is, & lt; = Delphi 2007), then you should see the ANI functions (
* A ) instead of Eu Code Functions (
* W ).
- relative The path is
Comments
Post a Comment