W
wana
I use mkdir in a program which recursively searches through a
directory searching for files of a particular type and recreating the
directory structure elsewhere and the files (which happen to be images
which get manipulated by ImageMagick along the way).
In recreating the directory structure, I sometimes come across the
error:
No such file or directory
which is due to trying to create multiple directory levels at once
which is not allowed. While this probably is a problem in my program
logic (that is another whole issue, but I didn't want to ask too much
at once), I was wondering, why can't I create a whole path at once
like:
mkdir mouse/cat/dog
where none of the three directories exist yet.
This is what I came up with, but I thought there might be another way
or a better way to do it.
sub SuperMkdir
{
my $path = shift;
my $hold = $path;
while (mkdir($path) == 0)
{
do
{
$path =~ s/[^\/]+\/*$//;
}
while (mkdir($path) == 0);
$path = $hold;
}
}
directory searching for files of a particular type and recreating the
directory structure elsewhere and the files (which happen to be images
which get manipulated by ImageMagick along the way).
In recreating the directory structure, I sometimes come across the
error:
No such file or directory
which is due to trying to create multiple directory levels at once
which is not allowed. While this probably is a problem in my program
logic (that is another whole issue, but I didn't want to ask too much
at once), I was wondering, why can't I create a whole path at once
like:
mkdir mouse/cat/dog
where none of the three directories exist yet.
This is what I came up with, but I thought there might be another way
or a better way to do it.
sub SuperMkdir
{
my $path = shift;
my $hold = $path;
while (mkdir($path) == 0)
{
do
{
$path =~ s/[^\/]+\/*$//;
}
while (mkdir($path) == 0);
$path = $hold;
}
}