So in creating a script to reorganize folder structure, I created this function. It works and its very simple, just wondering what you guys thought of it, and how I might be made better. What it does is takes a path and checks if it exists, if it does it ends, if not it checks the parent directory for existence. It then creates the missing directory structure.
function checkDir($path) {
if( is_dir($path) ) return;
$parent = dirname($path);
if( !is_dir($parent) ) checkDir($parent);
mkdir($path);
}
The one thing I haven't been able to figure out is how to error out if its impossible to make the directory. For example, I could pass Z:/somefolder to it and it wouldn't be able to create a Z drive heh, but if I pass C:/somefolder it will create somefolder without fail.
Thoughts? TIA