Similar to the C++ thread, how can I check if a file exists in Delphi?
It is the FileExists() function.
Here is a code sample from the help file to check if a file exists and then prompts for confirmation before deleting it:
Code:if FileExists(FileName) then if MessageDlg('Do you really want to delete ' + ExtractFileName(FileName) + '?'), mtConfirmation, [mbYes, mbNo], 0, mbNo) = IDYes then DeleteFile(FileName);
Use FileExists function. If file exists, then this function will return True.
procedure TForm1.Button1Click(Sender: TObject);
begin
if FileExists(Edit1.Text) then
ShowMessage('File already exists!')
else
ShowMessage('This file is unique');
end;
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks