Posted by John Ferguson on 1999-05-17
As for Perl-GTK I haven't used it.
But, here is a routine that will print out the files in a directory (recurses
through subdirectories).
Usage:
DisplayDirs(HEADER,DIRECTORY)
where HEADER is passed as a null string (not very good programming, but it
works). A tab character will be added for each level of recursion.
and DIRECTORY is the initial directory to start listing.
I have actually included a call to the subroutine so you can just copy this into
a file and run it as it stands. If you want to create a list of files, just
declare a global array and start filling it. You can also throw in some
filtering that way. Just a thought.
#**********************PERL code here*******************************
DisplayDirs("",shift @ARGV);
sub DisplayDirs {
local ($header,$directory) = @_;
opendir (DIR,$directory) || die "Can't open $directory ($!)";
print $header."***".$directory."***\n";
#can be changed to put
the directories into a structure if desired
local @files = readdir(DIR); #read all the files in the directory
closedir (DIR);
$header .= "\t";
foreach $file (@files) {
if ( -d $directory.'/'.$file) { #check and see if it is a
directory
unless ($file =~ /\./) { #don't want to include . and ..
#Warning: will
skip any directory with '.' in the name
# this might be
a problem if these are allowed
DisplayDirs($header,$directory.'/'.$file);
}
} else { #can be changed to put
filenames into a structure - can add filters here as well
print "$header","./$file"."\n";
}
}
}
#**********************That's all
Previous post | Next post | Timeline | Home