Program that searches within text files

imported_KuJaX

Platinum Member
May 29, 2004
2,428
0
0
I have a bunch of websites that I am doing some coding for. There is a total of around 100+ files, and sometimes I need to find what specific file has a specific string (.php).

What is the industry standard as far as indexing these files, and searching within these .php, .txt and .html files?
 

mugs

Lifer
Apr 29, 2003
48,920
46
91
Any decent text editor should have a search feature that can include all of the files in a directory (or below directory). EditPlus is one, I use it.
 

SagaLore

Elite Member
Dec 18, 2001
24,036
21
81
I just use the Windows search tool. :p But I'm sure I could write a batch script to do it too.
 

BigJ

Lifer
Nov 18, 2001
21,330
1
81
It's actually pretty easy to create a program that would read in the files and do just what you were looking for.
 

mugs

Lifer
Apr 29, 2003
48,920
46
91
Originally posted by: BigJ
It's actually pretty easy to create a program that would read in the files and do just what you were looking for.

Perl would be a good language to do it in. It even has a built-in grep function. :p
 

imported_KuJaX

Platinum Member
May 29, 2004
2,428
0
0
Originally posted by: mugs
Any decent text editor should have a search feature that can include all of the files in a directory (or below directory). EditPlus is one, I use it.



EditPlus i Just tried and seems to work fantastic!
 

zoiks

Lifer
Jan 13, 2000
11,787
3
81
$start_path = 'C:\Temp2';
&read_dir($start_path);
sub read_dir {
$start_path_loc = shift @_;
&print_file($start_path_loc) if (-f $start_path_loc && -e $start_path_loc);
if (-d $start_path_loc && -e $start_path_loc)
{
opendir(DH, $start_path_loc) or warn($! . " - $start_path_loc");
while ( defined (my $item_read = readdir DH) )
{

next if $item_read =~ /^\.\.?$/;
$start_path_loc = "$start_path_loc\\$item_read";
if (-d $start_path_loc && -e $start_path_loc)
{
&read_dir($start_path_loc);
print "$start_path_loc\n";

} elsif (-f $start_path_loc && -e $start_path_loc)
{
print "$start_path_loc\n";
$start_path_loc =~ s/(.*)\\.*$/\1/;
}
if (!$item_read)
{
$start_path_loc =~ s/(.*)\\.*$/\1/;
break;
}
}
}
}

sub print_file {
$filedir = shift @_;
print $filedir;
}



This should retrieve the files recursively in a directory structure. Needs modification though. You probably will need to change the regex to find the type of file and then pipe it into an input stream and then parse each line for the string (using another regex).