I got an array containing path names and file names
['css/demo/main.css', 'home.css', 'admin/main.css','account']
I want to create those files and folders if they are not existed yet. Overwrite them if they are already existed.
mkdirs() method to create a collection of directories recursively. It will create a directory with all its necessary parent directories.
Using the mkdir() Method File class and define a method named file() which internally makes use of the mkdir() function to recursively create directories.
makedirs() method in Python is used to create a directory recursively. That means while making leaf directory if any intermediate-level directory is missing, os. makedirs() method will create them all.
Alternatively referred to as recursive, recurse is a term used to describe the procedure capable of being repeated. For example, when listing files in a Windows command prompt, you can use the dir /s command to recursively list all files in the current directory and any subdirectories.
For each of this paths you'll have to specific whether it is a file or a directory. Or you could make your script assume, that the path is pointing to a file when the basename (the last part of the path) contains a dot.
To create a directory recursively is simple:
mkdir(dirname($path), 0755, true); // $path is a file
mkdir($path, 0755, true); // $path is a directory
0755
is the file permission expression, you can read about it here: http://ch.php.net/manual/en/function.chmod.php
<?php
function mkpath($path)
{
if(@mkdir($path) or file_exists($path)) return true;
return (mkpath(dirname($path)) and mkdir($path));
}
?>
This makes paths recursively.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With