develooper Front page | perl.beginners | Postings from March 2002

Re: Writing Dir Names into a File

Thread Previous
From:
John W. Krahn
Date:
March 29, 2002 17:13
Subject:
Re: Writing Dir Names into a File
Message ID:
3CA510F9.759CD6C4@acm.org
Garrett Esperum wrote:
> 
> So I have modified my script a bit and it works. However, now I want to not
> read in the "." and ".." directories. How can I do this?? I am having
> problems with this part.
> 
> I think my "while ( my $file = (!/^\.\.?$/,readdir( DIR )) )" part is wrong.
> Any suggestions??
> 
> Below is my new script:
> 
> #!/usr/local/bin/perl -w
> 
> use strict;
> 
> my $dir = '/directory_name';
>   opendir( DIR, $dir )
>      or die "Failed to open directory '/images': Error='$!'";
> while ( my $file = (!/^\.\.?$/,readdir( DIR )) ) {
>    open(OUT, ">>dir.txt") || die "Inside Func - Cant open dir.txt: $!\n";
>    print OUT "$file \n";
>    close(OUT);
> #   print "$file \n" if -d "$dir/$file";
> }


#!/usr/local/bin/perl -w
use strict;

my $dir = '/directory_name';
opendir( DIR, $dir )
    or die "Failed to open directory '/images': Error='$!'";

while ( defined( my $file = readdir DIR ) ) {
    next if $file =~ /^\.\.?$/;
    open(OUT, ">>dir.txt") || die "Inside Func - Cant open dir.txt:
$!\n";
    print OUT "$file \n";
    close(OUT);
#   print "$file \n" if -d "$dir/$file";
}


John
-- 
use Perl;
program
fulfillment

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About