How to exclude HTML extension

I use a script that list all recently updated files in directories. Actually
the script works fine but it list absolutely everything it founds, cgi, txt
etc.

I need it to list ONLY files ending with the extension .shtml

How can I modify the script?

I also would like to know how I can close the previous Q i asked, they were answered and there is no option available for me to give my points and unlocked the Q.


Thanks



++++++++++++++

Here it is:

# full path to the directory you want to view
$dir_path = "/www/web/mysite/directory/";

# full internet url that points to that directory
$internet_url_to_dir = "http://www.mysite.com/directory;

# if you wish to traverse subdirectories, make this value 1, otherwise make
it 0
$traverse_subdirectories = 1;

# only display the files updated in the last ?? days
# (set to 10000 if no time restriction desired)
$updates_boundary = 7; #days

###### YOU NEED NOT MODIFY ANYTHING BELOW THIS POINT ######

$| = 1; #no buffering of output
$add_path = "";

# remove / from end of paths if present
$dir_path =~ s/\/$//;
$internet_url_to_dir =~ s/\/$//;

print "Content-type: text/html\n\n<html><title>Directory listing of "
 . "$internet_url_to_dir</title><body bgcolor=white><h2>Directory listing of
"
 . "$internet_url_to_dir</h2>last modification is listed next to the
file<br><br>\n";

$sep = "";


GETDIR: {
 opendir(DIR,"$dir_path$sep$add_path")
  or print "<font color=red>can't open directory
$dir_path$sep$add_path</font><br>\n";
 push @files, map { $_ = "$add_path$_"; } grep !/^\.+/, readdir DIR;
 closedir(DIR);
 push @dirs, grep {-d "$dir_path/$_"} @files;



 @files = grep {-T "$dir_path/$_" and (-M "$dir_path/$_") <
$updates_boundary} @files;
 if ($traverse_subdirectories and scalar @dirs) {
  $add_path = (shift @dirs)."/";
  $sep = "/";
  redo GETDIR;
 }
}

foreach $file (sort { -M "$dir_path/$a" <=> -M "$dir_path/$b" } @files) {
 print "<a href='$internet_url_to_dir/$file'>$file</a> ",
  &formatTime((stat "$dir_path/$file")[9]),"<br>\n";
}

print "</body></html>\n";

sub formatTime {
 my ($min,$hour,$day,$mon,$year) = (localtime $_[0])[1..5];
 $mon++;
 $year %= 100;
 return "$mon/$day/$year $hour:".sprintf("%02d",$min);
}


wireframAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
ozoConnect With a Mentor Commented:
You seem to looking for subdirectories when you
  push @dirs, grep {-d "$dir_path/$_"} @files;
and I'd imagine that most subdirectory names wouldn't end in .shtml,
so perhaps you want to exclude extensions at a different point?
You can do
  @files = grep {/\.shtml$/} @files;
when you want only files ending with the extension .shtml in @files
0
 
ozoCommented:
grep /\.shtml$/, readdir DIR
0
 
wireframAuthor Commented:
grep /\.shtml$/, readdir DIR

result is the script doesn't read through all directories, stop after printing the 2 first lines:

Directory listing of
modification is listed next to the
file




0
 
wireframAuthor Commented:
grep /\.shtml$/, readdir DIR

result is the script doesn't read through all directories, stop after printing the 2 first lines:

Directory listing of
modification is listed next to the
file




0
 
wireframAuthor Commented:
Thanks a lot Ozo.

It was exactly the problem, the script couldn't read directories because of the extension!

Thanks again!
0
All Courses

From novice to tech pro — start learning today.