[Perl] Dir structure
Nimster
nimster at netvision.net.il
Mon Jan 28 04:08:58 PST 2002
Dir structureThe shell command "tree" could help you.
There's File::Find like Gabor pointed out, and my very own MP3 file lister, which could be adapted for your need:
#!/bin/perl -w
use CGI qw(:all);
use strict;
print header;
my $mp3dir="/home/nimster/music/"; #change this to your filedir
my @subs=&findfiles($mp3dir);
sub findfiles {
my ($currdir)=@_;
opendir(MP3ROOTDIR, $currdir);
my @allfiles=grep(!/^\.\.?$/, readdir MP3ROOTDIR);
closedir(MP3ROOTDIR);
my @subdirs=grep(!/.*\..*/, @allfiles);
my @rootfiles=grep(/.*\.mp3/i, @allfiles); #change extension to whatever you want...
$currdir=~/^.*\\(music.*)$/; my $pathdir=$1; #this just beautifies the output a bit
print "<h1>$1</h1>";
foreach (@rootfiles) {
my $file=substr($_, 0, -4); #cuts the .mp3 extension...
print "<A href=\"$pathdir\\$_\"> $file <\/a> <BR>"; #prints them as links
}
print "<BR>";
foreach (@subdirs) {
&findfiles("$currdir\\$_");
}
return @subdirs;
}
-Nimster
----- Original Message -----
From: Yaron Golan
To: 'perl at perl.org.il'
Sent: Monday, January 28, 2002 12:20 PM
Subject: [Perl] Dir structure
Hi all,
Do you know (or have) where can I find a script that gets a root directory and prints its directory structure under it?
Thanks in advance,
YG
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://perl.org.il/pipermail/perl/attachments/20020128/bfb574ed/attachment.htm
More information about the Perl
mailing list