Help with script to list non-html files in folder
Help with script to list non-html files in folder
am 27.10.2005 23:00:03 von Mac
Hi
I have this code but it does not seem to list non-html files.
Could anyone point me in the right direction.
Thanks in advance
Mark
#!/usr/bin/perl
print "Content-type: text/html\n\n";
# Define Variables
$basedir = '../';
$baseurl = 'http://www.mywebsite.co.uk/';
@files = (*.zip');
$title = "My Web Site";
# Get Files To Search Through
&get_files;
# Print Results of Search
&return_html;
sub get_files {
chdir($basedir);
foreach $file (@files) {
$ls = `ls $file`;
@ls = split(/\s+/,$ls);
foreach $temp_file (@ls) {
if (-d $file) {
$filename = "$file$temp_file";
if (-T $filename) {
push(@FILES,$filename);
}
}
elsif (-T $temp_file) {
push(@FILES,$temp_file);
}
}
}
}
sub return_html {
print "\n";
print "
\n";
print "Directory\n";
print "\n";
print "\n";
print "Contents of folder:\n";
foreach $FILE (@FILES) {
print "
\n";
}
print "";
print "\n";
}
Re: Help with script to list non-html files in folder
am 28.10.2005 01:05:13 von someone
mac wrote:
> Hi
Since you are not using modules or asking a question about modules what made
you decide that comp.lang.perl.modules was the correct newsgroup for this?
> I have this code but it does not seem to list non-html files.
What error or warning messages do you get? What does it "seem to list"?
> Could anyone point me in the right direction.
>
>
>
> #!/usr/bin/perl
Since this is a CGI program you should use taint mode and you should also
enable warnings and strict.
#!/usr/bin/perl -T
use warnings;
use strict;
> print "Content-type: text/html\n\n";
> # Define Variables
> $basedir = '../';
> $baseurl = 'http://www.mywebsite.co.uk/';
> @files = (*.zip');
^^
You are missing a quote.
> $title = "My Web Site";
>
> # Get Files To Search Through
> &get_files;
Why are you using a subroutine for code that will only run once? Why are you
using Perl4 style subroutine calls?
> # Print Results of Search
> &return_html;
>
> sub get_files {
>
> chdir($basedir);
You should verify that chdir() worked correctly.
> foreach $file (@files) {
> $ls = `ls $file`;
Is the ls command available? Why not use perl's built-in opendir/readdir or
glob functions?
> @ls = split(/\s+/,$ls);
What if your file names contain whitespace? Why not just use backticks in
list context?
> foreach $temp_file (@ls) {
> if (-d $file) {
> $filename = "$file$temp_file";
You are missing a directory separator between $file and $temp_file.
> if (-T $filename) {
> push(@FILES,$filename);
> }
> }
> elsif (-T $temp_file) {
> push(@FILES,$temp_file);
> }
> }
> }
> }
>
> sub return_html {
> print "\n";
> print "
\n";
> print "Directory\n";
> print "\n";
> print "\n";
>
> print "Contents of folder:\n";
>
> foreach $FILE (@FILES) {
> print "
\n";
> }
>
> print "";
> print "\n";
>
> }
John
--
use Perl;
program
fulfillment
Re: Help with script to list non-html files in folder
am 28.10.2005 11:29:06 von metaperl
Mac,
I suggest you use File::Find, which is a stnadard part of Perl:
http://search.cpan.org/author/NWCLARK/perl-5.8.7/lib/File/Fi nd.pm
mac wrote:
> Hi
>
> I have this code but it does not seem to list non-html files.
>
> Could anyone point me in the right direction.
>
> Thanks in advance
>
> Mark
>
>
>
> #!/usr/bin/perl
> print "Content-type: text/html\n\n";
> # Define Variables
> $basedir = '../';
> $baseurl = 'http://www.mywebsite.co.uk/';
> @files = (*.zip');
> $title = "My Web Site";
>
> # Get Files To Search Through
> &get_files;
>
> # Print Results of Search
> &return_html;
>
> sub get_files {
>
> chdir($basedir);
> foreach $file (@files) {
> $ls = `ls $file`;
> @ls = split(/\s+/,$ls);
> foreach $temp_file (@ls) {
> if (-d $file) {
> $filename = "$file$temp_file";
> if (-T $filename) {
> push(@FILES,$filename);
> }
> }
> elsif (-T $temp_file) {
> push(@FILES,$temp_file);
> }
> }
> }
> }
>
> sub return_html {
> print "\n";
> print "
\n";
> print "Directory\n";
> print "\n";
> print "\n";
>
> print "Contents of folder:\n";
>
> foreach $FILE (@FILES) {
> print "
\n";
> }
>
> print "";
> print "\n";
>
> }
Re: Help with script to list non-html files in folder
am 29.10.2005 14:33:57 von Mac
I realise this is the wrong group and I have posted my message in
another group.
Thanks for taking the trouble to the repy
Mark