Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Overwrite Files..

Posted on 2001-07-10
13
Medium Priority
?
1,639 Views
Last Modified: 2007-12-19
I am copying dirs with the code above:
This code is copying dirs from time to time. But when it finds the file with the same name it asks overwrite? But i want to skip this part and automatically overwrite all files. How can i do this?


Procedure CopyDir(fromDir, toDir : String);
var
fileOp: TShFileOpStruct;
begin
FillChar(fileOp, Sizeof(TShFileOpStruct), 0);
fromDir := fromDir + '\*.*'#0;
toDir := toDir + #0;
with fileOp do begin
  wnd := Application.Handle;
  wfunc := FO_COPY;
  pFrom := PChar(fromDir);
  pTo := PChar(toDir);
  fFlags := FOF_ALLOWUNDO;
  fAnyOperationsAborted := false;
  hNameMappings := nil;
  lpszProgressTitle := nil;
end;
SHFileOperation(fileOp);
end;

// The Call:

CopyDir(Form1.Memo1.Text, Form1.Memo2.Text);
0
Comment
Question by:sophiesas
[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
  • 6
  • 3
  • 3
  • +1
13 Comments
 
LVL 13

Expert Comment

by:Epsylon
ID: 6268790
Use this:

fFlags := FOF_ALLOWUNDO or FOF_SILENT or FOF_NOCONFIRMATION;
0
 
LVL 5

Expert Comment

by:TheNeil
ID: 6268800
Have you tried adding FOF_NOCONFIRMATION to the fFlags property of the fileOp structure? It's Windows that's asking for confirmation and if you need to get around it then you might have to forget about using the API call and write your own dedicated code (not too tough BTW)

The Neil =:)
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 13

Expert Comment

by:Epsylon
ID: 6268803
Maybe you want to leave out FOF_SILENT....
0
 
LVL 2

Expert Comment

by:egono
ID: 6270008
just for my interest - does the SHFileOperation() return immediatly or does it wait until all files copied?
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 6270067
As long as you use non-relative path names you can more or less count on it. The filesystem knows which files/dirs are being deleted, copied, etc.
0
 
LVL 2

Expert Comment

by:egono
ID: 6270121
Epsylon - was your last comment a answer for my question? if yes - sorry I don't get it, does it return immediatly or not?
if not - don't mind ...
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 6270245
Sorry for the confusion, it was a reply to you egono.

The MSN docs say that when you use relative path names, it's not thread safe. This means that when a process/thread does a fileoperation, another may not see that correctly. Use ExpandUNCFileName to create a qualitied path.

In other words, SHFileOperation can return before the modification are done physically, but the filesystem/shell keeps track of (caches) these modifications.
0
 

Author Comment

by:sophiesas
ID: 6272301
i can't get it work please add you comments to my code..
0
 

Author Comment

by:sophiesas
ID: 6272303
Please give examples...

Thankx
0
 
LVL 13

Accepted Solution

by:
Epsylon earned 200 total points
ID: 6272519
Procedure CopyDir(fromDir, toDir : String);
var
fileOp: TShFileOpStruct;
begin
  FillChar(fileOp, Sizeof(fileOp), 0);
  fromDir := fromDir + '\*.*';
  toDir := toDir;
  with fileOp do begin
    wnd := Application.Handle;
    wfunc := FO_COPY;
    pFrom := PChar(fromDir + #0);
    pTo := PChar(toDir + #0);
    fFlags := FOF_ALLOWUNDO or FOF_NOCONFIRMATION;
    fAnyOperationsAborted := false;
    hNameMappings := nil;
    lpszProgressTitle := nil;
  end;
  SHFileOperation(fileOp);
end;
0
 
LVL 2

Expert Comment

by:egono
ID: 6272567
epsylon - thanks!
0
 

Author Comment

by:sophiesas
ID: 6277102
epsylon thanks very much..
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

610 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