Solved

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

Posted on 2006-11-27
3
245 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 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month7 days, 13 hours left to enroll

632 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