Solved

copy files in delphi

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

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

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

690 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