Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2006-11-27
3
Medium Priority
?
246 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
[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 28

Accepted Solution

by:
2266180 earned 2000 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
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

722 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