Get correct relative path in Delphi

I am writing with Delphi 2009 a small application for editing HTML files. Through

HypRef := '../../photos/myjpg.jpg'   
If FileExists(ExpandFileName(HypRef)) then ... 

      

I can find out if a file exists or not. Is there a function to find out the correct relative path if FileExists gives a negative answer?

+2


source to share


1 answer


I am assuming you are in the directory of the main HTML document. You can call SetCurrentDir () on the directory containing the main HTML document, or just add this path to the relative one.

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

      



You don't really need to call ExpandFileName (), since the OS will correctly resolve ".." and ".". pieces. However, if you intend to use a path for identification, they must all be cannonized using ExpandFileName ().

+10


source







All Articles