Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Check if a file exists?

delphi

  • Please log in to reply
3 replies to this topic

#1 Lop

Lop

    Speaks fluent binary

  • Just Joined
  • PipPipPipPipPipPipPip
  • 1112 posts

Posted 12 August 2006 - 09:07 AM

Similar to the C++ thread, how can I check if a file exists in Delphi?
  • 0

#2 BuildPromoteWin

BuildPromoteWin

    CC Newcomer

  • Just Joined
  • PipPip
  • 10 posts

Posted 15 August 2006 - 06:56 PM

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:

if FileExists(FileName) then
  if MessageDlg('Do you really want to delete ' + ExtractFileName(FileName) + '?'), mtConfirmation, [mbYes, mbNo], 0, mbNo) = IDYes then 
    DeleteFile(FileName);

  • 0

#3 Guest_priorityone_*

Guest_priorityone_*
  • Guest

Posted 06 January 2007 - 03:27 AM

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;
  • 0

#4 John

John

    CC Mentor

  • Moderator
  • 4450 posts
  • Location:New York, NY

Posted 06 January 2007 - 10:54 PM

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;


We appreciate your help, but this issue was solved four months ago in the post above yours. Please try not to bring back dead topics as its not tolerated :cool:
  • 0





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download