?
Solved

copy files in delphi

Posted on 1998-03-20
5
Medium Priority
?
310 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
[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
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 200 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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…
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses
Course of the Month11 days, 11 hours left to enroll

752 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