Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Perl Beginners Cgi > Process Directo...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 1 Topic 1448 of 1478
Post > Topic >>

Process Directory and subdirectories Recursively

by mimicafe@[EMAIL PROTECTED] (Mimi Cafe) Jan 28, 2008 at 11:56 AM

------=_Part_5422_6868365.1201521365325
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Hi,

I am trying to process a directory and all subdirectory recursively and
generate a list as the Unix command "ls -R" will display, but this seems
not
to behave as it should.
My script only goes as far as processing the directory and the 1 step
below
not more.

I have some like, but the script goes as far as 1_child and 2_child but no
further:
/parent/1_child/1_grant_child/././
/parent/2_child/2_grant_child/././

The script will finally be used on Windows OS,  Unix system command cannot
be used.

Can anyone help?

Regards

Mimi

###############################################################
#!/usr/bin/perl -w


# Recursively read content of a folder and dynamically create a list on an
html page.

use CGI qw(:standard);
#use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
#use warnings;
use strict;



print header(),
 start_html("Do***ents list");
print "<h1> Do***ents List</h1><br>\n";

my $source = "/depot/my_directory";

opendir (SOURCE, $source) or die "Cannot open the source folder for
reading:
$!\n";

my $file;
while (defined($file = readdir(SOURCE))){
 next if $file =~ /^\.{1,2}$/;
 my $full_name = "$source/$file";
 if (-d $full_name){
  #my $full_name = "$source/$file";
  print qq(<b>$file</b><br>);
  process($full_name);
 }else{
  print qq(<a href="$full_name>$file</a><br>);
 }
 #next;
}
closedir (SOURCE);


print end_html();



# Subroutine to process subdirectory and list content.

sub process{

 my ($path, $file, @[EMAIL PROTECTED]
 $file_full_path);
 $path = ****ft;
 opendir (SUBDIR, $path) or die "Cannot open the subfolder for reading:
$!\n";

 @[EMAIL PROTECTED]
 = sort grep {!/^\.{1,2}$/} readdir(SUBDIR);
 closedir (SUBDIR);

 for (@[EMAIL PROTECTED]
){
  $file_full_path = "$path/$_";

  if (-d $_){
   print qq(<b>$_</b><br />);
   process($_);


  }else {

   print qq(<a href="$file_full_path">$_</a><br />);

  }

 }


}
#######################################################

------=_Part_5422_6868365.1201521365325--
 




 1 Posts in Topic:
Process Directory and subdirectories Recursively
mimicafe@[EMAIL PROTECTED  2008-01-28 11:56:05 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 25 18:58:31 CDT 2008.