Solved

How to copy all contents of a cd(except for two folders) to harddrive superfast?

Posted on 2006-11-27
3
240 Views
Last Modified: 2010-04-05
Hi folks!

What is the fastest function or procedure to copy an entire cd (excluding two folders) to my harddrive?

Currently my code copies the entire cd contents and afterwards it deletes the folders that I didn't want. But since those folders measure up to 130 MB I think I better search for some other workaround ;-)

One assumption > using the windows api for this copying thing and having it display all filenames slows down the copying I reckon? using xxcopy would be faster?

Kind regards,

Peter

The working sample equals 500 points
0
Comment
Question by:PeterdeB
  • 2
3 Comments
 
LVL 28

Accepted Solution

by:
2266180 earned 500 total points
ID: 18020391
here is some code that works. you'll need to edit the hardocded stuff from teh test app ;)

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

function hasExclude(list:tstrings; name:string):boolean;
var i:integer;
begin
  result:=false;
  if list=nil then
    exit;
  i:=0;
  name:=lowercase(name);
  while (i<list.Count) and (name<>lowercase(list[i])) do
    inc(i);
  result:=i<list.count;
end;

procedure copyFiles(src, dst:string; exclude:TStrings);
var r:tsearchrec;
begin
  if fileexists(dst) then
  begin
    DeleteFile(dst);// this will overwrite the file
    dst:=ExtractFilePath(dst);
  end;
  dst:=IncludeTrailingPathDelimiter(dst);
  if FileExists(src) then
  begin
    CopyFile(pansichar(src), pansichar(dst), false);
    exit;
  end;
  if not DirectoryExists(src) then
    raise exception.create('directory '+src+ ' not found.');
  src:=IncludeTrailingPathDelimiter(src);
  ForceDirectories(dst);
  if findfirst(src+'*.*', faanyfile-favolumeid, r)=0 then
  repeat
    if not hasExclude(exclude, src+r.name) then
    begin
      if (r.Attr and fadirectory=fadirectory) then
      begin
        if (r.Name<>'.') and (r.Name<>'..') then
          copyFiles(src+r.name, dst+r.name, exclude);
      end                                     else
        CopyFile(pansichar(src+r.name), pansichar(dst+r.name), false);
    end;
  until findnext(r)<>0;
  findclose(r);
end;

procedure TForm1.Button1Click(Sender: TObject);
var l:tstringlist;
begin
  l:=tstringlist.create;
  l.Add('c:\test1\testing');
  copyfiles('c:\test1', 'c:\test2', l);
  l.free;
end;

end.
0
 

Author Comment

by:PeterdeB
ID: 18028630
Works like a charm exactly what I needed thanks a bunch!!

Kind regards,

Peter ;-)

Ps since the copying is an intensive and lengthy operation, should I use application.processmessages?
0
 
LVL 28

Expert Comment

by:2266180
ID: 18030076
if you files are big, then I suggest moving the whole function into a thread. if you also want progress, then you wil have to give up the copyfile function and write one your own and then communicate from the thread to the main app the progress. or just use applicaiton.processmessages but make sure the user will not click twice on the copy button ;)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

947 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now