in reply to Creating new folders
My usual way to ensure that a directory exists is:
my $dir = ...; if ( ! -d $dir && ! mkdir $dir ) { die "Can't mkdir '$dir': $!"; }
This reads fairly naturally to me as "if it's not there, and I can't make it, die with a good error message." If you're concerned that the directory above the one you want might not be there (and therefore would block you trying to create the one you want), look at mkpath in File::Path.
For your particular case, where you want to do this with multiple directories, I'd probably put the directories in a list and then loop over that.
my @wanted_directories = ( "e:/web/public_html/eagle_f91/ffinfo/protected/images/$Game", "e:/web/public_html/eagle_f91/ffinfo/protected/images/$Game/$S +ubSet", "e:/web/public_html/eagle_f91/ffinfo/protected/images/$Game/$S +ubSet/thmb" ); foreach my $dir ( @wanted_directories ) { if ( ! -d $dir && ! mkdir $dir ) { die "Can't mkdir '$dir': $!"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Creating new folders
by Anonymous Monk on Feb 03, 2008 at 10:57 UTC |