Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Wildcard

Posted on 1997-06-19
4
Medium Priority
?
271 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 150 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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

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…
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…
Screencast - Getting to Know the Pipeline
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

927 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