Domain Empire

Print out a link to each file in a directory with Perl

NameSilo
Watch
Impact
6
This little snippet will print out a link to each file in the directory you specify as the $dirpath

Code:
#!/usr/bin/perl -w
#SIMPLE LINK CREATOR 

use CGI::Carp qw(fatalsToBrowser);

#the server path to the directory with the files
my $dirpath = '/path/to/directory';

opendir DIR, $dirpath || die $!;
my @directory = readdir DIR;
closedir DIR;

print "Content-type: text/htmlnn";
foreach my $file (@directory) {
my $links = qq~<a href="$file">$file</a><br><br>n~;
print $links;
}
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back