Solved

File Exists on save?

Posted on 2000-04-17
10
276 Views
Last Modified: 2010-04-04
How do I showmessage to user if they are trying to save over an existing file?

<Filename> already exists, Do you wish to replace it?
          <Yes>    <No>


A full example please :)
0
Comment
Question by:fibdev
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 6

Expert Comment

by:Jaymol
ID: 2723514
If FileExists(FileName) then
  If MessageDlg(FileName+' exists.  Are you sure you wish to save?',
                mtConfirmation, [mbYes, mbNo], 0)=mrYes then begin
    ...
    Do Save Stuff
    ...
  end else begin
    ...
    Do stuff if not saving
   ...
  end;
0
 
LVL 2

Expert Comment

by:rene100
ID: 2723528
var
Ant: integer;
begin
if FileExists(Filename) then
   begin
   Ant:=MessageDlg'File '+Filename+'    already exists. Do you wish to replace it?',mtConfirmation,[mbYes,mbNo],0);
if ant=mryes then
   begin    
   //overwrite
   end;
else
   begin  
   //don't overwrite
   end;
end;

regards
rene
0
 
LVL 2

Expert Comment

by:rene100
ID: 2723531
sorry jaymol, didn't see your comment...;-)
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Author Comment

by:fibdev
ID: 2723601
How do I keep the savedialog open if they say no?
0
 
LVL 15

Expert Comment

by:simonet
ID: 2723624
A much better/easier way is to use the TSaveFileDialog component, since it can handle that sorta thing automatically.

Alex
0
 
LVL 3

Author Comment

by:fibdev
ID: 2723641
I don't have TSaveFileDilog, I don't think ...

I use Delphi 5 Standard
0
 
LVL 3

Author Comment

by:fibdev
ID: 2723643
I have TReplaceDialog but since Delphi is new to me, I don't know how to use it :(
0
 
LVL 2

Expert Comment

by:NetoMan
ID: 2723743
fibdev:

"...How do I keep the savedialog open if they say no?..."

are you trying to say that if they don't want to replace they have to save the file with other name ?

then just put what jaymol or rene write in a loop sentence like :

goingOut = FALSE;
repeat

 / * here routine to ask file name */

 If FileExists(FileName) then
   If MessageDlg(FileName+' exists.  Are you sure you wish to save?',
                mtConfirmation, [mbYes, mbNo], 0)=mrYes then begin
     ...
     /* Do Save Stuff */
     goingOut = TRUE;
     ...
   end;
until goingOut;

NetoMan :}
0
 
LVL 4

Accepted Solution

by:
jeurk earned 50 total points
ID: 2723809
Hello,
they is nothing to do, just set the options ofOverwritePrompt to true :
ofOverwritePrompt      Generates a warning message if the user tries to select a file name that is already in use, asking whether to overwrite the existing file. (Use with TSaveDialog and TSavePictureDialog.)
That's all.
0
 
LVL 3

Author Comment

by:fibdev
ID: 2724652
Thank you everyone for your input but this is exactly the solution i was looking for.

Neto, everyone, I will remember your input If I ever want more control than this for saving files.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question