Solved

copy files in delphi

Posted on 1998-03-20
5
292 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

757 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

19 Experts available now in Live!

Get 1:1 Help Now