我正在用 Delphi 2009 编写一个小应用程序来编辑 HTML 文件。和
HypRef := '../../photos/myjpg.jpg'
If FileExists(ExpandFileName(HypRef)) then ...
我可以找出文件是否存在。如果 FileExists 给出否定答案,是否有找出正确相对路径的功能?
我正在用 Delphi 2009 编写一个小应用程序来编辑 HTML 文件。和
HypRef := '../../photos/myjpg.jpg'
If FileExists(ExpandFileName(HypRef)) then ...
我可以找出文件是否存在。如果 FileExists 给出否定答案,是否有找出正确相对路径的功能?
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().