SPUG: Yet another silly question

Brian Aker brian at tangent.org
Sat Jan 19 17:12:50 CST 2002


On Sat, 2002-01-19 at 14:22, Susanne Bullo wrote:
> Ok, I am trying to figure out the coding for checking to see if a directory
> exists and if it doesn't, create it.  I've gotten out my "Perl For Dummies"
> book and did a lot of searching and am still stumped.  Anyone have a quick
> and easy answer for me?
#!/usr/bin/perl -w
use strict;

if ( -e $ARGV[0] ) {
	if (-d $ARGV[0]) {
		print "Directory exists\n";
	} else {
		print "A file exists where you want a directory\n";
	}
	mkdir($ARGV[0]);
} else {
	mkdir($ARGV[0]);	
}


A bit verbose. If you need to create multiple directories look at
File::Path.
	-Brian

-- 
_______________________________________________________
Brian Aker, brian at tangent.org 
Slashdot Senior Developer
Seattle, Washington
http://tangent.org/~brian/
http://askbrian.org/
_______________________________________________________
You can't grep a dead tree.


 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     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