σΟϨΫτϦύεΛࢦఆ͢ΔͱWarning
makeDirectory('test/foo/bar');
//Warning: mkdir(): No such file or directory in /usr/
local/code/mkdir.php on line 9
• testσΟϨΫτϦɺfoo σΟϨΫτϦ͕ଘࡏ͠ͳ͍߹
Warning͕ൃੜ͢Δ
• σΟϨΫτϦ࡞͞Εͳ͍
σΟϨΫτϦ͕طʹଘࡏ͢ΔͱWarning
• ࡞લʹis_dir(),
fi
le_exists()ͰνΣοΫ͕ඞཁ
• ͜ΕϚχϡΞϧʹॻ͍ͯ͋Δ
makeDirectory('foo');
makeDirectory('foo');
// Warning: mkdir(): File exists in /usr/local/
code/mkdir.php on line 9
Slide 10
Slide 10 text
is_dir,
fi
le_existsΛ͏
function makeDirectory(string $path): bool
{
if (is_dir($path)) {
return true;
}
if (file_exists($path)) {
return false;
}
return mkdir($path, recursive: true);
}
✴
fi
le_exists() ͕ trueͷͱ͖݁ՌతʹσΟϨΫτϦ͕࡞Ͱ͖ͳ͍ͷͰҙ