<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Recursively creating directory structures</title>
	<atom:link href="http://aidanlister.com/2004/04/recursively-creating-directory-structures/feed/" rel="self" type="application/rss+xml" />
	<link>http://aidanlister.com/2004/04/recursively-creating-directory-structures/</link>
	<description>Code is poetry</description>
	<lastBuildDate>Tue, 09 Mar 2010 10:53:14 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Anonymous</title>
		<link>http://aidanlister.com/2004/04/recursively-creating-directory-structures/comment-page-1/#comment-534</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Fri, 31 Mar 2006 21:25:25 +0000</pubDate>
		<guid isPermaLink="false">http://aidanlister.com/?p=69#comment-534</guid>
		<description>if using win DIRECTORY_SEPARATOR will be \

but people coding will commonly still use \

if you pass a &#039;foo/bar/baz to your function, it will fail on win because it is trying to locate DIRECTORY_SEPARATOR with strrpos, which fails.


consider:
$pathname = str_replace(array(&#039;/&#039;, &#039;\\&#039;), DIRECTORY_SEPARATOR, $pathname);

[Editor&#039;s Note: Good pick up. Fixed, thanks!]</description>
		<content:encoded><![CDATA[<p>if using win DIRECTORY_SEPARATOR will be \</p>
<p>but people coding will commonly still use \</p>
<p>if you pass a &#8216;foo/bar/baz to your function, it will fail on win because it is trying to locate DIRECTORY_SEPARATOR with strrpos, which fails.</p>
<p>consider:<br />
$pathname = str_replace(array(&#8216;/&#8217;, &#8216;\\&#8217;), DIRECTORY_SEPARATOR, $pathname);</p>
<p>[Editor's Note: Good pick up. Fixed, thanks!]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mercedes</title>
		<link>http://aidanlister.com/2004/04/recursively-creating-directory-structures/comment-page-1/#comment-308</link>
		<dc:creator>Mercedes</dc:creator>
		<pubDate>Wed, 13 Apr 2005 22:19:39 +0000</pubDate>
		<guid isPermaLink="false">http://aidanlister.com/?p=69#comment-308</guid>
		<description>Nice 1 Mate Came in real handy, couldnt find the thing anywhere.</description>
		<content:encoded><![CDATA[<p>Nice 1 Mate Came in real handy, couldnt find the thing anywhere.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Cbelin</title>
		<link>http://aidanlister.com/2004/04/recursively-creating-directory-structures/comment-page-1/#comment-288</link>
		<dc:creator>Cbelin</dc:creator>
		<pubDate>Thu, 31 Mar 2005 17:04:57 +0000</pubDate>
		<guid isPermaLink="false">http://aidanlister.com/?p=69#comment-288</guid>
		<description>Great function !!! But I found another one which is simpler :

&lt;?php
function mkdirr($path)
// create a directory structure recursively
{
	if(is_dir($path)) return true;
	return mkdirr(dirname($path)) &amp;&amp; @mkdir($path);
}
?&gt;</description>
		<content:encoded><![CDATA[<p>Great function !!! But I found another one which is simpler :</p>
<p>&lt;?php<br />
function mkdirr($path)<br />
// create a directory structure recursively<br />
{<br />
	if(is_dir($path)) return true;<br />
	return mkdirr(dirname($path)) &#038;&#038; @mkdir($path);<br />
}<br />
?&gt;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Treehousetim</title>
		<link>http://aidanlister.com/2004/04/recursively-creating-directory-structures/comment-page-1/#comment-266</link>
		<dc:creator>Treehousetim</dc:creator>
		<pubDate>Sat, 19 Mar 2005 02:24:22 +0000</pubDate>
		<guid isPermaLink="false">http://aidanlister.com/?p=69#comment-266</guid>
		<description>I use php under windows (CLI) however, I use forward slashes exclusively as this will still remain compatible with *nix systems.

The php manual states that:
&quot;On Windows, both slash (/) and backslash (\) are used as path separator character. In other environments, it is the forward slash (/).&quot;

A small change to this function will make this function work on both windows and *nix.

put this line at the top of the function:
$pathname = str_replace( &quot;\\&quot;, &quot;/&quot;, $pathname );

then where $next_pathname is set, use a &quot;/&quot; in place of the constant or variable

I made this change on my system and it works fine.

Thanks for a nice, very useful function.

-Tim Gallagher

[Editor&#039;s Note: By using the DIRECTORY_SEPARATOR separator constant, we avoid the need to hardcode any specific slash.]</description>
		<content:encoded><![CDATA[<p>I use php under windows (CLI) however, I use forward slashes exclusively as this will still remain compatible with *nix systems.</p>
<p>The php manual states that:<br />
&#8220;On Windows, both slash (/) and backslash (\) are used as path separator character. In other environments, it is the forward slash (/).&#8221;</p>
<p>A small change to this function will make this function work on both windows and *nix.</p>
<p>put this line at the top of the function:<br />
$pathname = str_replace( &#8220;\\&#8221;, &#8220;/&#8221;, $pathname );</p>
<p>then where $next_pathname is set, use a &#8220;/&#8221; in place of the constant or variable</p>
<p>I made this change on my system and it works fine.</p>
<p>Thanks for a nice, very useful function.</p>
<p>-Tim Gallagher</p>
<p>[Editor's Note: By using the DIRECTORY_SEPARATOR separator constant, we avoid the need to hardcode any specific slash.]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nematia</title>
		<link>http://aidanlister.com/2004/04/recursively-creating-directory-structures/comment-page-1/#comment-265</link>
		<dc:creator>Nematia</dc:creator>
		<pubDate>Thu, 17 Mar 2005 21:16:06 +0000</pubDate>
		<guid isPermaLink="false">http://aidanlister.com/?p=69#comment-265</guid>
		<description>Thank you for your help</description>
		<content:encoded><![CDATA[<p>Thank you for your help</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aidan Dotgeek</title>
		<link>http://aidanlister.com/2004/04/recursively-creating-directory-structures/comment-page-1/#comment-202</link>
		<dc:creator>Aidan Dotgeek</dc:creator>
		<pubDate>Fri, 04 Feb 2005 02:39:13 +0000</pubDate>
		<guid isPermaLink="false">http://aidanlister.com/?p=69#comment-202</guid>
		<description>Another slight variation.  True single function return, and function name is now mkdirTree.

&lt;?php
	/**
	 * Create a directory structure recursively
	 *
	 * @author      Aidan Lister &lt;aidan@php.net&gt;
	 * @version     1.0.0
	 * @param       string   $pathname    The directory structure to create
	 * @return      bool     Returns TRUE on success, FALSE on failure
	 */
 	function mkdirTree($pathname, $mode = null) {

		$dirSeperator = &quot;/&quot;;
		$return = false;

	    // Check if directory already exists
    	if (is_dir($pathname) &#124;&#124; empty($pathname)) {
        	$return = true;
	    }
 		else {
	    	// Ensure a file does not already exist with the same name
		    if (is_file($pathname)) {
    		    trigger_error(&#039;mkdirTree() Directory $pathname already exists&#039;, E_USER_WARNING);
        		$return = false;
		    }
 			else {
	    		// Crawl up the directory tree
		    	$nextPathname = substr($pathname, 0, strrpos($pathname, $dirSeperator));
	    		if ($this-&gt;mkdirTree($nextPathname, $mode)) {
    	    		if (!file_exists($pathname) and strpos($pathname, &quot;.htm&quot;) == 0) {
    	    			echo &quot;Making directory $pathname...&lt;br&gt;&quot;;
        	    		$return = mkdir($pathname, $mode);
		        	}
		    	}
			}
		}


	    return $return;
	}
?&gt;</description>
		<content:encoded><![CDATA[<p>Another slight variation.  True single function return, and function name is now mkdirTree.</p>
<p>&lt;?php<br />
	/**<br />
	 * Create a directory structure recursively<br />
	 *<br />
	 * @author      Aidan Lister &lt;aidan@php.net&gt;<br />
	 * @version     1.0.0<br />
	 * @param       string   $pathname    The directory structure to create<br />
	 * @return      bool     Returns TRUE on success, FALSE on failure<br />
	 */<br />
 	function mkdirTree($pathname, $mode = null) {</p>
<p>		$dirSeperator = &#8220;/&#8221;;<br />
		$return = false;</p>
<p>	    // Check if directory already exists<br />
    	if (is_dir($pathname) || empty($pathname)) {<br />
        	$return = true;<br />
	    }<br />
 		else {<br />
	    	// Ensure a file does not already exist with the same name<br />
		    if (is_file($pathname)) {<br />
    		    trigger_error(&#8216;mkdirTree() Directory $pathname already exists&#8217;, E_USER_WARNING);<br />
        		$return = false;<br />
		    }<br />
 			else {<br />
	    		// Crawl up the directory tree<br />
		    	$nextPathname = substr($pathname, 0, strrpos($pathname, $dirSeperator));<br />
	    		if ($this-&gt;mkdirTree($nextPathname, $mode)) {<br />
    	    		if (!file_exists($pathname) and strpos($pathname, &#8220;.htm&#8221;) == 0) {<br />
    	    			echo &#8220;Making directory $pathname&#8230;&lt;br&gt;&#8221;;<br />
        	    		$return = mkdir($pathname, $mode);<br />
		        	}<br />
		    	}<br />
			}<br />
		}</p>
<p>	    return $return;<br />
	}<br />
?&gt;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jared Kuolt</title>
		<link>http://aidanlister.com/2004/04/recursively-creating-directory-structures/comment-page-1/#comment-164</link>
		<dc:creator>Jared Kuolt</dc:creator>
		<pubDate>Fri, 07 Jan 2005 07:23:38 +0000</pubDate>
		<guid isPermaLink="false">http://aidanlister.com/?p=69#comment-164</guid>
		<description>As per the &#039;return once&#039; convention, I have modified the function to return once:
&lt;?php
function mkdirr($pathname, $mode = null)
{
    $return = false;

    // Check if directory already exists
    if (is_dir($pathname) &#124;&#124; empty($pathname)) {
        $return = true;
    }

    // Ensure a file does not already exist with the same name
    if (is_file($pathname)) {
        trigger_error(&#039;mkdirr() File exists&#039;, E_USER_WARNING);
        $return = false;
    }

    // Crawl up the directory tree
    $next_pathname = substr($pathname, 0, strrpos($pathname, DIRECTORY_SEPARATOR));
    if (mkdirr($next_pathname, $mode)) {
        if (!file_exists($pathname)) {
            $return = mkdir($pathname, $mode);
        }
    }

    return $return;
}

?&gt;</description>
		<content:encoded><![CDATA[<p>As per the &#8216;return once&#8217; convention, I have modified the function to return once:<br />
&lt;?php<br />
function mkdirr($pathname, $mode = null)<br />
{<br />
    $return = false;</p>
<p>    // Check if directory already exists<br />
    if (is_dir($pathname) || empty($pathname)) {<br />
        $return = true;<br />
    }</p>
<p>    // Ensure a file does not already exist with the same name<br />
    if (is_file($pathname)) {<br />
        trigger_error(&#8216;mkdirr() File exists&#8217;, E_USER_WARNING);<br />
        $return = false;<br />
    }</p>
<p>    // Crawl up the directory tree<br />
    $next_pathname = substr($pathname, 0, strrpos($pathname, DIRECTORY_SEPARATOR));<br />
    if (mkdirr($next_pathname, $mode)) {<br />
        if (!file_exists($pathname)) {<br />
            $return = mkdir($pathname, $mode);<br />
        }<br />
    }</p>
<p>    return $return;<br />
}</p>
<p>?&gt;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anonymous</title>
		<link>http://aidanlister.com/2004/04/recursively-creating-directory-structures/comment-page-1/#comment-145</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Sat, 25 Dec 2004 16:36:55 +0000</pubDate>
		<guid isPermaLink="false">http://aidanlister.com/?p=69#comment-145</guid>
		<description>good stuff</description>
		<content:encoded><![CDATA[<p>good stuff</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael Ochs</title>
		<link>http://aidanlister.com/2004/04/recursively-creating-directory-structures/comment-page-1/#comment-142</link>
		<dc:creator>Michael Ochs</dc:creator>
		<pubDate>Wed, 22 Dec 2004 23:21:34 +0000</pubDate>
		<guid isPermaLink="false">http://aidanlister.com/?p=69#comment-142</guid>
		<description>Nice function! I found you link on php.net! Very helpfull, it saved my day! ;)</description>
		<content:encoded><![CDATA[<p>Nice function! I found you link on php.net! Very helpfull, it saved my day! <img src='http://aidanlister.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jyotin</title>
		<link>http://aidanlister.com/2004/04/recursively-creating-directory-structures/comment-page-1/#comment-138</link>
		<dc:creator>Jyotin</dc:creator>
		<pubDate>Thu, 16 Dec 2004 22:25:33 +0000</pubDate>
		<guid isPermaLink="false">http://aidanlister.com/?p=69#comment-138</guid>
		<description>how to call this funtion</description>
		<content:encoded><![CDATA[<p>how to call this funtion</p>
]]></content:encoded>
	</item>
</channel>
</rss>
