Nishi Bhonsle wrote: > > Hi: > Sorry to start this thread again, but it would not have been wise to ask my > related question in a different thread. > I tried to run the program on a windows machine, apparently the regex in > question only lists directories within directories and not the files within > the directories. > I tried Rob's regex as well as Randal's. > In addition how can I modify the code, so that the buildlist.txt only lists > the files within the directories and not the directories? > > TIA! > > -------------------------------------------------------------------------------- ----------------------------------------------- > > > use strict; > use warnings; > > my $path = $ARGV[0]; > > opendir DIR, $path or die "Can't open $path: $!"; > > my @new = grep /[^.]/, readdir DIR; #tried this > #my @new = grep { $_ ne "." and $_ ne ".." } readdir DIR; #tried this too. > closedir DIR; > > open FILE,">c:/buildlist.txt"; > print FILE "$_\n" foreach @new; #this only lists directories within > directories and not the files within the directories > close FILE; > > open(FILE2,">>c:/final.txt"); > > foreach my $file (@new) { > my $record = qq("SL/$file" "%ORACLE_HOME%/server/bin/$file" "$file" > NA\n); > print $record; > print FILE2 $record; > } > > close FILE2;
Hi again Nishi. I think somebody mentioned it before, but what you need is File::Find. This code will put into @new the names of all the files in and below $path. use strict; use warnings; use File::Find; my @new; find(sub {push @new, $File::Find::name}, $path); print "$_\n" foreach @new; Now beware that all files and directories are included. I've never been sure whether you were interested in the directory names, and if you want to filter out the directories and leave just the files, change the call to find() like this: find(sub {push @new, $File::Find::name if -f}, 'E:/Games/Darwinia/'); This solution has the advantage that File::Find doesn't return the pseudo- directories '.' and '..' so we have nothing to worry about on that score :) HTH, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>