Solved

Using TSHFileOpStruct to copy files

Posted on 2004-08-06
3
4,599 Views
Last Modified: 2008-01-09
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.SpeedButton4Click(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].Selected = 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.BackupSchijfnummer.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].Selected := False;
           Vrij:= DiskFree(Datamodule1.BackupSchijfnummer.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
0
Comment
Question by:marioway
[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
  • 2
3 Comments
 
LVL 7

Expert Comment

by:LRHGuy
ID: 11740038
Make this minor change:

   fFlags:= FOF_NoConfirmMKDir or FOF_NoConfirmation;

I believe the file will be written over with no notification. (That's what you want?)

0
 

Author Comment

by:marioway
ID: 11741897
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
0
 
LVL 7

Accepted Solution

by:
LRHGuy earned 125 total points
ID: 11742996
That is a different problem! The copy is file by file. You have to figure out on your own what has been deleted in one directory then delete it in the other.

Or, you could simply delete the target directory (D:), then copy C: to D:, then it will be a more exact copy.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month7 days, left to enroll

623 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