Bioinfocoder has asked for the wisdom of the Perl Monks concerning the following question:
another sub-folder./rootdir ./rootdir/folder1 has files file1.txt, file2.txt,file3.txt..etc
My script should create a list of files inside each subfolder, with path to all files corresponding to that subfolder like -./rootdir/folder2 has files file1.txt, file2.txt,file3.txt..etc too
My code is not generating any file in the subfolders, can someone please point out the error EDITED code - Now my code is generating files in within each subdirectory, But the array (@subdirs) creates a key for the main directory (here ./rootdir) as well. How can I ignore reading this directory in array and just read the subdirectories using File::Find./rootdir/folder1/List1.txt ./rootdir/folder2/List2.txt
use strict; use warnings; use File::Find::Rule; my $directory = './rootdir'; my @subdirs = File::Find::Rule->directory->in( $directory ); foreach my $dir (@subdirs) { #print "$dir\n"; next if ($dir eq ".."); if (-d $dir) { my $curr_dir = $dir; open (my $OUTFILE, '>>', "$curr_dir/List.txt") or die "Cant op +en '$dir.txt!' $!"; my @files = File::Find::Rule->file() ->name( '*.*' ) -> in( $d +ir); foreach $_ (@files) { print $OUTFILE "$_\n"; } close $OUTFILE; } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: creating a list of files under each subfolder in a main directory
by GrandFather (Saint) on Mar 17, 2016 at 20:33 UTC | |
by Anonymous Monk on Mar 18, 2016 at 00:51 UTC | |
by Bioinfocoder (Novice) on Mar 18, 2016 at 14:18 UTC | |
|
Re: creating a list of files under each subfolder in a main directory
by Discipulus (Canon) on Mar 17, 2016 at 20:18 UTC | |
by Bioinfocoder (Novice) on Mar 18, 2016 at 03:44 UTC | |
|
Re: creating a list of files under each subfolder in a main directory
by Laurent_R (Canon) on Mar 17, 2016 at 23:47 UTC | |
|
Re: creating a list of files under each subfolder in a main directory
by akuk (Beadle) on Mar 18, 2016 at 12:37 UTC |