Reputation: 27
I want to create a folder in a particular path using mkdir
.
Upvotes: 2
Views: 9684
Reputation: 1012
You can also use:
my $dir = "../../folder/my_dir";
# if dir not exists create it
unless (-d "$dir") {`mkdirhier $dir`;}
Upvotes: 0
Reputation: 9
this syntax will check for directory existence and create it if needed
# here include path to new directory name
$newdir = './directory_name';
opendir(DIR, $newdir) || mkdir($newdir,0777) || die "Cannot create directory $newdir; $!";
Upvotes: -1
Reputation: 386361
Assuming D:/Test/Data
exists
my $dir_qfn = 'D:/Test/Data/foo';
mkdir($dir_qfn)
or $!{EEXIST} # Don't die if $dir_qfn exists.
or die("Can't create directory \"$dir_qfn\": $!\n");
If if might not,
use File::Path qw( make_path );
my $dir_qfn = 'D:/Test/Data/foo';
make_path($dir_qfn);
Upvotes: 5