Re: Recursively create directories
| From: | Adam Wright | Date: | Tue, 15 May 2001 11:14:06 +0000 |
| Subject: | Re: Recursively create directories | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-52833@lists.php.net to get a copy of this message | ||
This should do what you want...
$dir = "dir1/dir2/dir3/dir4";
$dir_array = explode("/",$dir);
$full_path = "";
foreach($dir_array as $current_dir) {
$full_path .= "/$current_dir";
if (!is_dir($DOCUMENT_ROOT . $full_path)) {
mkdir($DOCUMENT_ROOT."/" .$full_path,0700);
}
}
adamw
----- Original Message -----
From: "Darin Isola" <shag_bot@yahoo.com>
To: <php-general@lists.php.net>
Sent: Monday, May 14, 2001 8:01 PM
Subject: [PHP] Recursively create directories
> hi all,
>
> does anyone have a function to recursively create directories?
>
> heres what I have so far:
>
> $dir = "dir1/dir2/dir3/dir4";
> $dir_array = explode("/",$dir);
>
> foreach($dir_array as $current_dir) {
> if(! is_dir($DOCUMENT_ROOT."/".$current_dir) ) {
> mkdir($DOCUMENT_ROOT."/".$current_dir,0700);
> }
> }
>
> which works, but this will only create these dirs off the document
> root, not recursivley underneth one another. im getting stuck on how
> to remember what directory has been created and travel down from there.
>
> can anyone help a brother out?
>
>
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Auctions - buy the things you want at great prices
> http://auctions.yahoo.com/
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>
>