Solved

Wildcard

Posted on 1997-06-19
4
262 Views
Last Modified: 2010-04-04
I'm trying to write a small program that will read all the files in a directory search for a certain word, if the word is found inside the text file, the program will copy the line containing the word into another text file.

I have no problem doing this on ONE file, my question is, is there a way to make the program go throught all the files with a certain extension (let's say .txt) found in a directory.

ie : is there a way to give Delphi 2.0 program the path to the directory and tell it to execute a block of code on '*.txt'

so if the directory I want searched is c:\list
and it contains the 20 files (or more) with the 'txt' extension, I want the program to go throught each one of those 20 (or more)files.

Thanks in advance
Rafy Terzian
0
Comment
Question by:rafy
  • 2
  • 2
4 Comments
 
LVL 5

Accepted Solution

by:
ronit051397 earned 50 total points
ID: 1337247
Use the functions 'FindFirst' and 'FindNext'. This functions support wildcards.
0
 

Author Comment

by:rafy
ID: 1337248
This seems to be what I need...but it works on Ttable..
How do I place all the file names from my directory c:\list into a Ttable

What and how define all this??

Some code would be appreciated...
0
 
LVL 5

Expert Comment

by:ronit051397
ID: 1337249
when you call findfirst and findnext, the results are entered into a record of type TSearchRec, which includes data about the current file (name, size etc.).

then you call the append and set the appropriate field to
(name of TSearchRec).Name

from delphi help:
-------------------------
Unit
SysUtils
TSearchRec defines file information searched for by FindFirst or FindNext.

type
TFileName = string;
TSearchRec = record
Time: Integer;
Size: Integer;
Attr: Integer;
Name: TFileName;
ExcludeAttr: Integer;
FindHandle: THandle;
FindData: TWin32FindData;
end;


0
 

Author Comment

by:rafy
ID: 1337250
Thanks
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
This video discusses moving either the default database or any database to a new volume.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

759 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