Hello, your code is very confusing: especially the nested open part. You are opening for read every file in each subdirectory and while reading them (ie for every line!) you open a file in append mode and write the content of the line to it...

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)"

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

In reply to Re: creating a list of files under each subfolder in a main directory by Discipulus
in thread creating a list of files under each subfolder in a main directory by Bioinfocoder

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.