Jump to content

Finding files that contain a specific string


Recommended Posts

Hi guys ,

I have a directory that has thousands of txt files, from that directory , i need to find a file that contains a specific string ,return the file name.

Is there a way to do that in autoit ?

Any help is greatly appreciated.

Link to comment
Share on other sites

StringInStr ( "string", "substring" [, casesense [, occurrence [, start [, count]]]] )

help file, you can also use the help file to find information on the functions that you will need to read a list of the file names and how to create a for loop to check them.

Interpreters have great power!Although they live in the shadow of compiled programming languages an interpreter can do anything that a compiled language can do, you just have to code it right.

Link to comment
Share on other sites

StringInStr ( "string", "substring" [, casesense [, occurrence [, start [, count]]]] )

help file, you can also use the help file to find information on the functions that you will need to read a list of the file names and how to create a for loop to check them.

Thanks for the fast reply , but I dont want to checks if a string contains a given substring.

What I am trying to do it to find a file that contains a specific string

Link to comment
Share on other sites

If you want to do an search like this it's going to have to break down like this (or something close)

1: Figure out what files to scan and pass their filenames to a function (I'd use an array of file names and loop them to a function, personally)

2: Do this to each file and store the result:

A: Read the file into a variable

B: Use the suggested StringInStr to check

C: Return something or other to let you know that file contained the word

3: Pop up some sort of dialog letting you know if it was found

The major problems/variations are going to be in part A:

You can read the whole thing in and check it all at once (Possibly faster) but will bork if you have files bigger than can fit into memory

Or

You can read each line of the file in and check each line (Possible slower)

Either way, it's totally doable, but you'll definitely want to test it on a small number of files first, because searching thousands of files is going to take quite a bit of time.

Side note: if you do this sort of thing alot, you might be better off looking into the tools that are part of the Cygwin package.

#fgpkerw4kcmnq2mns1ax7ilndopen (Q, $0); while ($l = <Q>){if ($l =~ m/^#.*/){$l =~ tr/a-z1-9#/Huh, Junketeer's Alternate Pro Ace /; print $l;}}close (Q);[code] tag ninja!

Link to comment
Share on other sites

Use a desktopsearch application capable of reading the contents of .txt files :mellow: I don't think AutoIt will do it very fast, although it is capable of doing this. Just doesn't seem like an AutoIt task to me. Windows Desktop Search indexes .txt files just fine, which will give you extreme fast lookups (compared to some AutoIt script).

Or try Grep for Windows, I haven't tried it myself but this should work as well.

Edited by dani
Link to comment
Share on other sites

Or try Grep for Windows, I haven't tried it myself but this should work as well.

Grep is one of the utilities in the Cygwin packages, didn't know it was available separately.

Also, grep is considerably more powerful that the Windows Search, and using it will teach you regular expressions, which are invaluable when working with AutoIt

#fgpkerw4kcmnq2mns1ax7ilndopen (Q, $0); while ($l = <Q>){if ($l =~ m/^#.*/){$l =~ tr/a-z1-9#/Huh, Junketeer's Alternate Pro Ace /; print $l;}}close (Q);[code] tag ninja!

Link to comment
Share on other sites

Low-tech way: from Scite, Ctrl Shift F done.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...