Solved

Find and copy some files...

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

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…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

706 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

18 Experts available now in Live!

Get 1:1 Help Now