If you want to display relative paths in your application, you can use the ExtractRelativePath function.
This takes two parameters the base path, and the file path you wish to make relative, and returns you the relative path.
eg.
MyAppPath := 'c:\program files\toflidium\MyApp\';
MyFilePath := 'c:\program files\toflidium\MyApp\Bin\MyFile.bin';
RelPath := ExtractRelativePath(MyAppPath, MyFilePath);
RelPath will be "Bin\MyFile.bin"
Now if you want to expand this again to a fully qualified file name, and you use ExpandFileName you would think you would get the same filename back again, but not necessarily. This function uses the current directory so you might get back a path like "c:\my documents\bin\myfile.bin"
Solution
While I was playing with this, I noticed that if you add the relative path to the application path (or other path you used to make it relative) you get the path your looking for.
Thats Obvious I hear you cry!
Yes! However it also works for paths that move up the tree so
RelPath := ExtractRelativePath('C:\program files\toflidium\MyApp\',
'C:\program files\Microsoft Office\Office\WordFile.dot');
RelPath will be '..\..\Microsoft Office\Office\WordFile.dot'
You can add this to your Path and use it as a normal file name and it works perfectly.
ExpRelFile := 'C:\program files\toflidium\MyApp\..\..\Microsoft Office\Office\WordFile.dot'
eg.
if fileexists(ExpRelFile ) then ....
I dont know if this works on all versions of windows (I guess it does, because I'm sure it is based on DOS).
Hope someone finds this useful.
Toby Allen.