SPUG: test directory and then create

garrett esperum shamonsflame at hotmail.com
Wed Jan 9 18:06:49 CST 2002


Thanks For you help! I tried your example and it almost did the job. It 
successfully open and reads the external file. However it is not able to 
create any of the directories. This is the error message I recieve for the 
directory path one/two/three":

"Can't create directory: 'one/two/three No such file or directory."

-garrett

>From: Benjamin Turner <bjturner at mac.com>
>Reply-To: Benjamin Turner <bjturner at bigfoot.com>
>To: "garrett esperum" <shamonsflame at hotmail.com>
>CC: spug-list at pm.org
>Subject: Re: SPUG: test directory and then create
>Date: Wed, 9 Jan 2002 15:31:55 -0800
>
>
>On Wednesday, January 9, 2002, at 02:59  PM, garrett esperum wrote:
>
>>Hello all,
>>
>>I am using solaris 2.6 and perl 5.6.1.
>>I have an external file that has multiple directory names
>>listed in it. The directory names in this file are seperated by
>>a tab. I want to read this external file and I want to test to
>>see if each of these directories exists. If these directories
>>don't exist I want to create them. If they do exist I don't
>>want to do anything.
>>How do I do this in PERL? How do I do the dir test? And how do
>>I perform the loop?
>
>	Something like this ought to do the trick (untested):
>
>
>my( $directory, $permissions );
>
>local( $/ ) = "\t";                          # read file as
>though tabs are line-endings
>
>$permissions = 0700;
>
>while ( defined( $directory = <> ) ) {
>      chomp( $directory );           # remove tab from end of
>directory name, if it's present
>      if ( not -d $directory ) {     # check if directory exists
>(note: false if path points to a file)
>           mkdir( $directory, $permissions ) or warn "Can't
>create directory '$directory': $!\n";
>      }
>}
>
>
>--
>Benjamin John Turner          |  bjturner at bigfoot.com
>http://www.usfca.edu/turner/  |  bjturner at whowhere.com
>
>"The happiest of people don't necessarily have the best of
>everything; they just make the most of everything that comes
>along their way."
>




_________________________________________________________________
MSN Photos is the easiest way to share and print your photos: 
http://photos.msn.com/support/worldwide.aspx


 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
     Seattle Perl Users Group (SPUG) Home Page: http://zipcon.net/spug/





More information about the spug-list mailing list