marioway
asked on
Using TSHFileOpStruct to copy files
Hi, I have a problem. When I copy a file from a ShellListView1 (Drive c: for instance) to another drive (D: for instance), and the file I want to copy is already on D:, the file is not overwritten. No questions are asked wether to allow to overwrite te file with the newer one. How can I do this ?
Here is the code.
procedure TJawsieback.SpeedButton4Cl ick(Sender : TObject);
var FOS: TSHFileOpStruct;
A, B: string;
i: integer ;
begin
try
B:= ShellTreeView2.Path;
SpeedButton3.Enabled:= False;
ShellTreeView2.Root:= B;
for i:= 0 to ShellListView1.Items.Count -1 do begin
if ShellListView1.Items.Item[ i].Selecte d = True then begin
Label4.Caption:= 'Schrijven gegevens naar de Bestemmings-schijf';
A:= ShellListView1.Folders[i]. PathName ;
DirectorySize(A);
GetHugeFileSize(A);
Label5.Caption:= IntToStr(DirectorySize(A)) ;
Label16.Caption:= IntToStr(GetHugeFileSize(A ));
Vrij:= DiskFree(Datamodule1.Backu pSchijfnum mer.Value) ;
Label6.Caption:= IntToStr(vrij);
with FOS do begin
wFunc:= FO_COPY;
pFrom:= PChar(A + #0);
pTo:= PChar(B + #0);
fFlags:= FOF_NoConfirmMKDir;
SHFileOperation(FOS);
ShellListView1.Items.Item[ i].Selecte d := False;
Vrij:= DiskFree(Datamodule1.Backu pSchijfnum mer.Value) ;
end;
end;
end;
finally
ShellListView2.Update;
ShellTreeView2.Update;
SpeedButton3.Enabled:= True;
SpeedButton4.Visible:= False;
SpeedButton1.Enabled:= True;
Label6.Caption:= IntToStr(0);
Label5.Caption:= IntToStr(0);
Label4.Caption:= 'Backup voltooid';
end;
end;
Thx a lot
marioway
Here is the code.
procedure TJawsieback.SpeedButton4Cl
var FOS: TSHFileOpStruct;
A, B: string;
i: integer ;
begin
try
B:= ShellTreeView2.Path;
SpeedButton3.Enabled:= False;
ShellTreeView2.Root:= B;
for i:= 0 to ShellListView1.Items.Count
if ShellListView1.Items.Item[
Label4.Caption:= 'Schrijven gegevens naar de Bestemmings-schijf';
A:= ShellListView1.Folders[i].
DirectorySize(A);
GetHugeFileSize(A);
Label5.Caption:= IntToStr(DirectorySize(A))
Label16.Caption:= IntToStr(GetHugeFileSize(A
Vrij:= DiskFree(Datamodule1.Backu
Label6.Caption:= IntToStr(vrij);
with FOS do begin
wFunc:= FO_COPY;
pFrom:= PChar(A + #0);
pTo:= PChar(B + #0);
fFlags:= FOF_NoConfirmMKDir;
SHFileOperation(FOS);
ShellListView1.Items.Item[
Vrij:= DiskFree(Datamodule1.Backu
end;
end;
end;
finally
ShellListView2.Update;
ShellTreeView2.Update;
SpeedButton3.Enabled:= True;
SpeedButton4.Visible:= False;
SpeedButton1.Enabled:= True;
Label6.Caption:= IntToStr(0);
Label5.Caption:= IntToStr(0);
Label4.Caption:= 'Backup voltooid';
end;
end;
Thx a lot
marioway
ASKER
Hi, I tried it and it works fine for a single file, but I still have another problem: When I copy a directory from C: to D: , the first time everything is OK, even when I change the content of a file inside the directory on C: ; but when I delete for instance a file in the directory on C: and copy the directory to D: (where the first copy resides) , the file I deleted on C: is still visible in the directory on the D:. So I suppose the directory on the D: is not overwritten (?!).
thx
marioway
thx
marioway
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
fFlags:= FOF_NoConfirmMKDir or FOF_NoConfirmation;
I believe the file will be written over with no notification. (That's what you want?)