I want to retrieve a list of files in a given directory.
I take the directory path through an HTML form. This directory path has to be passed on to a cgi/perl file which should in turn return a list of all files in that particular path.
Kindly suggest some function for this issue.
PS : Development box is on WINDOWS
I am an amateur at Perl. check the code snippets i tried.
Trial.ipl
=============
#!c:\iw-home/iw-perl/bin/iwperl
use CGI;
my $cgi = new CGI;
print $cgi->header('text/html');
if (defined $cgi->param('ok')) {
my %params = $cgi->Vars;
print "My name is: ${params{filepath}}
";
} else {
print qq(
Trial
filepath :
);
}
mycgi.ipl
==============================
#!c:\iw-home/iw-perl/bin/iwperl
use CGI;
my $cgi = new CGI;
print $cgi->header('text/html');
if (defined $cgi->param('ok')) {
my %params = $cgi->Vars;
print "My Filepath is: ${params{filepath}}
";
$stat=opendir(IMD,$params{filepath}) || die("could not open");
print "\n Contents of the directory is \n";
@theFiles=readdir(IMD);
foreach(
@theFiles){
print $_. "\n \n ";
}
}