in reply to creating a list of files under each subfolder in a main directory
Meaningfull names for variables and a correct indentation (perltidy) help a lot reading code or maintain it after a while.
If your usage of File::Find::Rule is correct (you grab first level or nested dirs?) you can try something like:
# untested foreach my $dir (@subdirs) { # if you have .. you have also . next if ($dir eq "."); next if ($dir eq ".."); my @files = File::Find::Rule->file()->name('*.*')->in($dir); # compose a filename: # you probably need a path not just a name; you have not cd to + the inside directory # many module can hadle this for you, but you can deal with a +relative path too my $outputname = "./$dir/List.txt"; # open ALWAYS a lexical FH using the 3 args form.. open my $lexical_filehandle, '>', $outputname or die "Cannot w +rite to $outputname"; # print each filename to the listfile print $lexical_filehandle "$_\n" for @files; close $lexical_filehandle; }#next dir will be processed
L*
PS you can also play with:
find . -type d -maxdepth 1 | perl -lne "system qq(ls $_ > ./$_/_list +.txt)"
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: creating a list of files under each subfolder in a main directory
by Bioinfocoder (Novice) on Mar 18, 2016 at 03:44 UTC |