First of all, don't worry about asking questions that you think are stupid.
Your code has a number of problems:
- The first open call will, AFAIK, always fail because you are chdir()ed to the directory that contains the directory you've just found. So you're trying to write to a file with the same name as a directory. See the section about "the wanted() function" in the File::Find manpage.
- I don't thint the space in "> $dir" is a good idea - do ">$dir" instead.
- What is $file? You only use it once as far as I can see. This is where use warnings; can help you.
Anyway, none of this really helps you solve your problem. I would put the directory listings in a separate directory. Take a look at this code (untested):
use strict;
use warnings;
use File::Find;
my $listings_dir = 'c:/listings';
find(\&callback, 'c:/tmp');
sub callback {
my $file = $_;
# Check to see if $file is a directory
if (-d $file) {
# Get a list of all the files in the directory (inefficient)
# (If you only want the filenames rather than paths as well,
# investigate using File::Basename. If you want just the files
# in a directory, and directories within the directory,
# consider putting grep { -f $_ } before the glob.
my (@files) = glob($File::Find::dir . "/$_/*");
# Save this list to a file
open LISTING, ">$listings_dir/list$_.txt";
print LISTING join ("\n", @files);
close LISTING;
}
}
Good luck with learning Perl. I strongly recommend learning Perl properly--get yourself a copy of "Learning Perl". Your investment in learning Perl will pay back very quickly.