giggle well at least there was one mistake in there.
I was getting worried that I was able to write code off the top of my head that actually worked :-)
Indeed the script needs error-checking (the thing that I am always going on about)
Here's an improved version:
function makedir($sDir)
{
echo "Checking $sDir ... ";
if (file_exists($sDir))
{
if (is_dir($sDir))
{
echo "$sDirToMake already exists\n";
return 1;
}
else
{
echo "$sDirToMake is a file\n";
return 0;
};
}
else
{
mkdir ($sDir,0777);
return 1;
}
};
$path="/tmp/a/b/c";
split the path up into its subdirectories
If the path begins with a slash, skip it and prepend the slash to the first subdir
if($path[0]!="/")
{
$aDirs=split("/",$path);
}
else
{
$aDirs=split("/",substr($path,1));
$aDirs[0]="/".$aDirs[0];
};
Get the first directory to make.
Why do this sperately? because I will append the other
directories using a slash, and I don't want a slash for the first directory
$sDirToMake=$aDirs[0];
Make it
if (!makedir($sDirToMake))
{
echo "giving up.\n";
exit;
};
loop through the rest of the directories
for ($t=1;$t<count($aDirs);$t++)
{
Append a slash and the next directory
$sDirToMake.="/".$aDirs[$t];
#Make it or die trying
if (!makedir($sDirToMake))
{
echo "giving up.\n";
exit;
};
continue loop
};
exit;