Solved

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

Posted on 2006-11-27
3
239 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:
ciuly 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:ciuly
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

747 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

14 Experts available now in Live!

Get 1:1 Help Now