Solved

Find and copy some files...

Posted on 1998-05-30
4
166 Views
Last Modified: 2010-04-06
Help!
I want to find all the TXT-files (*.txt) in my TEMP-directory (c:\temp) and then copy them into another directory.
How can I fix that job? Please send me the source to do it...
Thanx!
SvR.
0
Comment
Question by:roosiedb
  • 2
4 Comments
 
LVL 3

Expert Comment

by:Matvey
ID: 1349291
Don't remember exactly, but go to the Delphi pages and find a component that searches for files. Then give it parameters and copy the found files using the Delphi file routines...

http://sunsite.icm.edu.pl/delphi/ 
http://www.delphideli.com/ 
http://torry.rimini.com/ 

I'll try to find exactly...
0
 

Author Comment

by:roosiedb
ID: 1349292
I don't want to use any components, I want to have some code to copy (for example) all the *.txt -files in a directory. This must be possible with some (I hope) simple code...
0
 
LVL 3

Expert Comment

by:Matvey
ID: 1349293
-Components come with sources. The copyfile procedure (or some other name) in Delphi is simple too. So just look at the source of the component to knwo how to find all files...
0
 
LVL 7

Accepted Solution

by:
ahalya earned 20 total points
ID: 1349294
you use  FindFirst, FindNext functions and "CopyFile" winapi.
( Matvey: not all components come with their source :-)

Here goes a sample proc.
//copies all files with name source.* to destn.* IF no EXT is given.
//otherwise copies source to destin.

procedure TMainForm.CopyMultipleFiles(source, destn:string);

var s1, s2 : string;
    Attr, Result : integer;
    SearchRec : TSearchRec;

begin;
if pos('.', source) = 0 then Source := Source + '.*';

Result := FindFirst(Source,  Attr, SearchRec);
While Result = 0 do
  begin
  s1 := ExtractFilePath(Source) + SearchRec.Name;
  s2 := ChangeFileExt(Destn, ExtractFileExt(SearchRec.Name));
  if not CopyFile(pchar(s1), pchar(s2), false) then
     begin;
     ShowMessage('Error Copying File: ' + S1);
     exit;
     end;
  Result := FindNext(SearchRec);
  end;
FindClose(SearchRec);
end;

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

809 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