Hello and thanks in advance for any assistance!!!

This is what I am trying to do which I thought would be straight forward but is causing me problems.

I am starting with a base directory that has many subdirectories under it, and those directories also have subdirectories, and I am trying to write to a file a list of all the subdirectories of any particular directory and an empty file if the directory has no subdirectories.

For instance: /about/ /about/me/ /about/you/ /about/me/myself/ would write a file in /about/ with me you a file in /you/ that is empty a file in /me/ with myself

I have tried a number of things but none are working so I am coming here for help

Thanks again for any help

Hello, I got it working. I was not returning to the find directory and that was causing the problem. Thanks for all the comments.

Here is the code, bad as it may be, for anyone else who might wish to do something similar.

#!c:/Perl/perl/bin/perl.exe use strict; use warnings; use FileHandle; use File::Find qw(find); use File::Basename; use File::Copy; use File::Find; use Cwd; my $BaseDir = 'C:/Temp3/jcr_root/content/acs/'; find( \&createContentxml, $BaseDir ); sub createContentxml { if (-d $File::Find::name) { my $dir = $File::Find::name; # print $dir . ": \n"; &subdir($dir) ; } } sub subdir { my $dir2 = getcwd; print $dir2 . "\n"; my $dir = $_[0]; chdir($dir) or warn " not able to cd into $dir \n"; print "dir: $dir: \n"; opendir DH, $dir or die "Failed to open $dir: $!"; while ($_ = readdir(DH)) { next if $_ eq "." or $_ eq ".."; if (-d $_ ) { print $_ . "\n"; open (MYFILE, '>>test7.txt'); print MYFILE $_ . "\n"; close (MYFILE); } else { next; } } open (MYFILE, '>>empty.txt'); print MYFILE " empty \n"; close (MYFILE); chdir($dir2); return 0; # Did not find any subdirectory in this directory }

In reply to listing all subdirectories of directory into file by tevolo

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.