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

Re: Writing Dir Names into a File

From:
garrett esperum
Date:
March 29, 2002 16:56
Subject:
Re: Writing Dir Names into a File
Message ID:
F4CrbreLDwdbWKEVqr40000803f@hotmail.com
Hello again,

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";
}

Thanks!!!

-garrett

>From: "garrett esperum" <shamonsflame@hotmail.com>
>To: beginners@perl.org
>Subject: Writing Dir Names into a File
>Date: Fri, 29 Mar 2002 12:42:59 -0800
>
>Hello all,
>
>Sorry about my previous message, I left alot of key info out. I am using
>Solaris 2.6. I want to read all of the directory names after $mydir, and
>then print those names into a file. How do I do this?
>
>Currently I have this as my script:
>
>#!/path/to/perl -w
>use strict;
>   my $dir = '/images';
>   opendir( DIR, $dir )
>      or die "Failed to open directory '/images': Error='$!'";
>while ( my $file = readdir( DIR ) ) {
>    print $file," is a directory!\n" if -d "$dir/$file";
>}
>
>I want to see other examples of how you do this. I haven't found much on 
>the
>web.
>
>Thanks Again!!
>
>-garrett
>
>_________________________________________________________________
>Chat with friends online, try MSN Messenger: http://messenger.msn.com
>
>
>--
>To unsubscribe, e-mail: beginners-unsubscribe@perl.org
>For additional commands, e-mail: beginners-help@perl.org
>




_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com




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