Solved

copy files in delphi

Posted on 1998-03-20
5
299 Views
Last Modified: 2010-04-06
Hi,
I want my users be to be able to make a backup of their data. Hence I have to write some code to copy all files in lets say c:\data to c:\data\backup. How can I best do this?
Thanks
0
Comment
Question by:lizzzard
5 Comments
 
LVL 4

Expert Comment

by:BoRiS
ID: 1360652
lizzzard try this function....

but remember to add LZexpand to your uses clause...

function CopyFile(SrcF,DestF : string) : boolean;
var
  SFile,
  DFile : integer;
  Res   : longint;
  Msg   : string;

begin
  SFile := FileOpen(SrcF,0);        { Open ReadOnly = 0, Write=1, Readwrite=2}
  DFile := FileCreate(DestF);
  Res := LZCopy(SFile,DFile);
  FileClose(SFile);
  FileClose(DFile);
  if Res < 0 then
  begin
    Msg := 'Unknown error';
    case Res of
      LZERROR_BADINHANDLE   : Msg := 'Invalid Source file handle';
      LZERROR_BADOUTHANDLE  : Msg := 'Invalid Destination file handle';
      LZERROR_BADVALUE      : Msg := 'Input parameter is out of range';
      LZERROR_GLOBALLOC     : Msg := 'Insufficient memory for the required buffers';
      LZERROR_GLOBLOCK      : Msg := 'Internal data structure handle invalid';
      LZERROR_READ          : Msg := 'Source file format is not valid';
      LZERROR_UNKNOWNALG    : Msg := 'The Source file was compressed with an unrecognized compression algorithm';
      LZERROR_WRITE         : Msg := 'There is insufficient space for the output file';
    end;
    MessageDlg(Msg,mtERROR,[mbOK],0);
    result := FALSE
  end else
    result := TRUE;
end;

Later
BoRiS
0
 
LVL 7

Expert Comment

by:ahalya
ID: 1360653
Why not do FindFirst, FindNext and call the WinAPI

copyFile(src, dst, FailIfExist) ?


0
 

Author Comment

by:lizzzard
ID: 1360654
I can't use LZExpand
0
 
LVL 3

Accepted Solution

by:
d4jaj1 earned 50 total points
ID: 1360655
There is a simple component caled uFileOps.  You can download it for Torry's site or post your email address here.  The component is free and allows you to do several file operations, including copying files very easily.  I use it my self and all I do to copy the files is write three lines of code -
Mask (eg *.db)
Loadfiles(false) - true adds teh full directory, false just teh files
Copyfiles - copies all of the files matching the mask above.

Pretty simple and comes with a help document.  If you need anymore answers from me, please post a comment here.  Good Luck!

Jay
0
 

Author Comment

by:lizzzard
ID: 1360656
Thanks d4jaj1 (what a name)

my email-adress is alexg@molyvos.net or give me the URL.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi: how to implement a User Shortcut mapper? 1 107
Working with hours 3 56
creating threads in delphi 1 101
FMX and jaudiotracker playing memory stream 29 77
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…
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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

813 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

18 Experts available now in Live!

Get 1:1 Help Now