sophiesas
asked on
Overwrite Files..
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);
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);
You can find the flags here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/shellcc/shell/structures/SHFILEOPSTRUCT.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/shellcc/shell/structures/SHFILEOPSTRUCT.asp
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 =:)
The Neil =:)
Maybe you want to leave out FOF_SILENT....
just for my interest - does the SHFileOperation() return immediatly or does it wait until all files copied?
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.
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 ...
if not - don't mind ...
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.
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.
ASKER
i can't get it work please add you comments to my code..
ASKER
Please give examples...
Thankx
Thankx
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
epsylon - thanks!
ASKER
epsylon thanks very much..
fFlags := FOF_ALLOWUNDO or FOF_SILENT or FOF_NOCONFIRMATION;