How can make a search in flat files?

Juniper

Platinum Member
Nov 7, 2001
2,025
1
0
I cannot use a database. I need to be able to manage the content of a website using flat files. And I need to be able to search for a keyword in those flatfiles. How the hell do I do that?!

I'm using ASP btw.
 

kt

Diamond Member
Apr 1, 2000
6,032
1,348
136
Perl is the best way to go for something like that. But if you really want to use ASP, then you'll have to use Scripting.FileSystemObject. Here's an sample:

Dim fso, tfo

Set fso = CreateObject("Scripting.FileSystemObject")
Set tfo = fso_OpenTextFile(filename, 1)

The thing is, you may only read one line at a time, so it's best if you read the whole file into an array. Here's how:

Dim count, textArray

count = -1

Do Until tfo.AtEndofStream
count = count +1

If count > UBound(textArray) Then ReDim Preserve textArray(count+1000)

textArray(count) = tfo.ReadLine
Loop

ReDim Preserve textArray(count)

Now, textArray contains all the text from your file.
 

singh

Golden Member
Jul 5, 2001
1,449
0
0
Any "Scripting" solution without a native code interface is bound to be quite slow.
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
Any "Scripting" solution without a native code interface is bound to be quite slow.

Not necessarily, it won't be as fast as a compiled solution but if the hardware is decently new it'll probably be fast enough. Perl probably has some of the worst startup times because of all the modules it has to load, but on a new machine it's still only a fraction of a second slower than a binary application. And if you use soemthing like mod_perl the startup time is only once per server start isntead of once per connection. I think ASP is handled the same as mod_perl, so the performance should be fine.