<?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: PHP Code To Check If A Directory Is Empty</title>
	<atom:link href="http://iarematt.com/php-code-to-check-if-a-directory-is-empty/feed/" rel="self" type="application/rss+xml" />
	<link>http://iarematt.com/php-code-to-check-if-a-directory-is-empty/</link>
	<description>technology &#38; software development blog by matt geri</description>
	<lastBuildDate>Fri, 18 Jun 2010 15:56:04 +0200</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Matt</title>
		<link>http://iarematt.com/php-code-to-check-if-a-directory-is-empty/comment-page-1/#comment-318</link>
		<dc:creator>Matt</dc:creator>
		<pubDate>Tue, 08 Dec 2009 14:36:53 +0000</pubDate>
		<guid isPermaLink="false">http://iarematt.com/?p=102#comment-318</guid>
		<description>I have updated the code in the above post to a more comprehensive example.</description>
		<content:encoded><![CDATA[<p>I have updated the code in the above post to a more comprehensive example.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matthias Hogerheijde</title>
		<link>http://iarematt.com/php-code-to-check-if-a-directory-is-empty/comment-page-1/#comment-317</link>
		<dc:creator>Matthias Hogerheijde</dc:creator>
		<pubDate>Tue, 08 Dec 2009 14:07:24 +0000</pubDate>
		<guid isPermaLink="false">http://iarematt.com/?p=102#comment-317</guid>
		<description>indentation doesn&#039;t seem to take...

and i wrote a mistake myself: it should be
while ($directory_empty [...]</description>
		<content:encoded><![CDATA[<p>indentation doesn&#8217;t seem to take&#8230;</p>
<p>and i wrote a mistake myself: it should be<br />
while ($directory_empty [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matthias Hogerheijde</title>
		<link>http://iarematt.com/php-code-to-check-if-a-directory-is-empty/comment-page-1/#comment-316</link>
		<dc:creator>Matthias Hogerheijde</dc:creator>
		<pubDate>Tue, 08 Dec 2009 14:06:06 +0000</pubDate>
		<guid isPermaLink="false">http://iarematt.com/?p=102#comment-316</guid>
		<description>Method 1 is a bit inefficient:

When you found 1 file or directory you can stop looping, you will loop trough the entire directory for all files in it. Won&#039;t be a problem with a small amount, but still. I would suggest something like:

$directory_empty = true;
$directory = dir(&#039;path_to_directory&#039;);  
while ($empty &amp;&amp; FALSE !== ($item = $directory-&gt;read())) {  
     if ($item != &#039;.&#039; &amp;&amp; $item != &#039;..&#039;) {  
         $directory_empty = false;  
     }  
} 

Furthermore, you forgot to declare $directory_empty and initialize it to true, both your methods will always result in a filled directory</description>
		<content:encoded><![CDATA[<p>Method 1 is a bit inefficient:</p>
<p>When you found 1 file or directory you can stop looping, you will loop trough the entire directory for all files in it. Won&#8217;t be a problem with a small amount, but still. I would suggest something like:</p>
<p>$directory_empty = true;<br />
$directory = dir(&#8217;path_to_directory&#8217;);<br />
while ($empty &amp;&amp; FALSE !== ($item = $directory-&gt;read())) {<br />
     if ($item != &#8216;.&#8217; &amp;&amp; $item != &#8216;..&#8217;) {<br />
         $directory_empty = false;<br />
     }<br />
} </p>
<p>Furthermore, you forgot to declare $directory_empty and initialize it to true, both your methods will always result in a filled directory</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andy P</title>
		<link>http://iarematt.com/php-code-to-check-if-a-directory-is-empty/comment-page-1/#comment-304</link>
		<dc:creator>Andy P</dc:creator>
		<pubDate>Fri, 13 Nov 2009 15:03:30 +0000</pubDate>
		<guid isPermaLink="false">http://iarematt.com/?p=102#comment-304</guid>
		<description>Method 1:

No, Geoff is right - think about it... 

if the filename is not &#039;.&#039; AND not &#039;..&#039; then it MUST be a file or directory (i.e. not the current dir or parent dir)

$item can&#039;t be equal to &#039;.&#039; and &#039;..&#039; at the same time, so ($item != &#039;.&#039; &#124;&#124; $item != &#039;..&#039;) will ALWAYS evaluate to TRUE!

Also you need to set
$directory_empty = TRUE; 
at the beginning, otherwise $directory_empty will remain unset and therefore always == FALSE</description>
		<content:encoded><![CDATA[<p>Method 1:</p>
<p>No, Geoff is right &#8211; think about it&#8230; </p>
<p>if the filename is not &#8216;.&#8217; AND not &#8216;..&#8217; then it MUST be a file or directory (i.e. not the current dir or parent dir)</p>
<p>$item can&#8217;t be equal to &#8216;.&#8217; and &#8216;..&#8217; at the same time, so ($item != &#8216;.&#8217; || $item != &#8216;..&#8217;) will ALWAYS evaluate to TRUE!</p>
<p>Also you need to set<br />
$directory_empty = TRUE;<br />
at the beginning, otherwise $directory_empty will remain unset and therefore always == FALSE</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt</title>
		<link>http://iarematt.com/php-code-to-check-if-a-directory-is-empty/comment-page-1/#comment-266</link>
		<dc:creator>Matt</dc:creator>
		<pubDate>Wed, 24 Jun 2009 21:44:38 +0000</pubDate>
		<guid isPermaLink="false">http://iarematt.com/?p=102#comment-266</guid>
		<description>Hey Geoff,

Thanks for the comment.

EDIT: You are correct, I have changed the code.</description>
		<content:encoded><![CDATA[<p>Hey Geoff,</p>
<p>Thanks for the comment.</p>
<p>EDIT: You are correct, I have changed the code.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Geoff</title>
		<link>http://iarematt.com/php-code-to-check-if-a-directory-is-empty/comment-page-1/#comment-265</link>
		<dc:creator>Geoff</dc:creator>
		<pubDate>Wed, 24 Jun 2009 03:42:18 +0000</pubDate>
		<guid isPermaLink="false">http://iarematt.com/?p=102#comment-265</guid>
		<description>In Method 1, I think you mean:

if ($item != &#039;.&#039; &amp;&amp; $item != &#039;..&#039;)</description>
		<content:encoded><![CDATA[<p>In Method 1, I think you mean:</p>
<p>if ($item != &#8216;.&#8217; &amp;&amp; $item != &#8216;..&#8217;)</p>
]]></content:encoded>
	</item>
</channel>
</rss>
