• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Program that searches within text files

imported_KuJaX

Platinum Member
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?
 
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.
 
It's actually pretty easy to create a program that would read in the files and do just what you were looking for.
 
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. 😛
 
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!
 
$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).
 
Back
Top