views:

422

answers:

1

Hi, I am writing with Delphi 2009 a little app to edit HTML files. With
HypRef := '../../photos/myjpg.jpg'
If FileExists(ExpandFileName(HypRef)) then ...
I can find out, whether the file exists or not. Is there a function to find out the correct relative path, if FileExists gives a negative answer?

+7  A: 

I'm presuming you mean relative to the directory of the main HTML document. You can call SetCurrentDir() to the directory containing the main HTML document, or you can simply prepend that path to the relative one.

if FileExists(ExtractFilePath(MainDocument) + HypRef) then...

You really don't need to call ExpandFileName() since the OS will properly resolve the '..' and '.' pieces. However, if you intend to use the path for identity then they should all be cannonicalized using ExpandFileName().

Allen Bauer