开发者

Get Correct Relative Path in Delphi

开发者 https://www.devze.com 2022-12-09 15:32 出处:网络
I am writing with Delphi 2009 a little app to edit HTML files. With HypRef := \'../../photos/myjpg.jpg\'

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 o开发者_如何学运维r not. Is there a function to find out the correct relative path, if FileExists gives a negative answer?


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().

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号