2

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?

4

1 に答える 1

10

私はあなたがメインのHTMLドキュメントのディレクトリに関連していることを意味していると思います。メインのHTMLドキュメントを含むディレクトリに対してSetCurrentDir()を呼び出すか、そのパスを相対パスの前に追加するだけです。

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

OSは「..」と「。」を適切に解決するため、ExpandFileName()を呼び出す必要はありません。ピース。ただし、IDにパスを使用する場合は、ExpandFileName()を使用してすべてを正規化する必要があります。

于 2009-10-25T20:46:35.023 に答える