You are both doing too much work and too little, assuming I understand what you are trying to achieve.
You don't need to open any files. You may need to recurse into sub-directories. Take a while to study the following code:
#!/usr/bin/perl use strict; use warnings; use File::Find::Rule; parseDir ('./rootdir'); sub parseDir { my ($dir) = @_; my @subdirs = File::Find::Rule->directory()->in($dir); parseDir ($_) for grep {!/^\.\.?$/ && $_ ne $dir} @subdirs; my @files = File::Find::Rule->file()->name('*.*')->in($dir); return if !@files; my $listFileName = ""; open my $listFile, '>', "$dir/List.txt" or return; print $listFile join "\n", @files, ''; }
The key to understanding it is that parseDir calls itself to deal with sub-directories. Having dealt with all sub-directories it then creates the list.txt file for the current directory.
In reply to Re: creating a list of files under each subfolder in a main directory
by GrandFather
in thread creating a list of files under each subfolder in a main directory
by Bioinfocoder
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |