Solved

Find and copy some files...

Posted on 1998-05-30
4
165 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

776 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