I need to make an HTML page that lists all files and directories and then links to them. The following script, with a subroutine, looks like what I need. I should just need to add some html tags to the Print statements.
Does that sound right to you all? Or do you have better suggestions? (I'm a real beginner at Perl, but my job has suddenly starting requiring lots of perl scripts!) --Deborah (I asked this question a while back, but my email messages got messed up and I can't find the answer that I got.) -----Original Message----- From: Beau E. Cox [mailto:[EMAIL PROTECTED] Sent: Tuesday, February 25, 2003 12:29 PM To: Prasad Karpur; [EMAIL PROTECTED] Subject: RE: How to look into every subdirectory Hi - > -----Original Message----- > From: Prasad Karpur [mailto:[EMAIL PROTECTED] > Sent: Tuesday, February 25, 2003 3:18 AM > To: [EMAIL PROTECTED] > Subject: How to look into every subdirectory > > > I am new to Perl and would like to know how to look into every > subdirectory. Any help would be greatly appreciated. > > #!/usr/bin/perl > > #use strict; > use Cwd; > > my $curr = cwd(); > opendir(CURRDIR, $curr) or die "can't open directory ($!), exiting.\n"; > > my @files = readdir(CURRDIR); > #closedir(CURRDIR); > > foreach my $file (sort @files) { > > next if $file eq '.' || $file eq '..'; > next if !-d $file; > > if (-d $file) { > print "$file/\n"; #Puts a slash in front of every directory > it encounters > } > else { print "$file\n"; } > > } > > > closedir(CURDIR); > Just use a recursive subroutine to traverse your directory tree from any starting point: traverse (cwd()); sub traverse { my $dir = shift; $dir .= '/' unless $dir =~ m{/$}; opendir (DIR, $dir) || die "unable to open directory $dir: $!\n"; my @contents = readdir (DIR); closedir (DIR); for my $item (sort @contents) { my $di = "$dir$item"; next unless (-d $di); next if ($item eq '.' or $item eq '..'); print "dir: $di\n"; traverse ($di); } for my $item (sort @contents) { my $di = "$dir$item"; next if (-d $di); print "file: $di\n"; } } Try the above; WARNING: may contain typos! :) Also - check out File::Find on CPAN. Aloha => Beau; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]