Skip to main content

Timeline for answer to How can I use PHP to check if a directory is empty? by André Fiedler

Current License: CC BY-SA 3.0

Post Revisions

8 events
when toggle format what by license comment
Apr 9, 2019 at 16:52 comment added Ashish Doneriya @AndréFiedler You are a genius, brilliant and responsible person. In all other answers, they first calculating total number of files and then checking if count > 0. But if a directory contains even one file, it is not empty.
Nov 20, 2018 at 17:49 comment added soger What I don't understand is why you say that it is better to use strict comparision when comparing to "." and "..". The readdir() function will always return a string (or the false) so I don't see the point. I'd also like to add that cleaning up after yourself is indeed always a good idea, one would think that after return when the $handle variable goes out of scope, closedir() would happen automatically but I just wrote a little test program, and it doesn't. Which is strange because other stuff, like flock do happen automatically.
Sep 28, 2016 at 6:37 comment added André Fiedler @BeatChristen Thx for the hint! Fixed it.
Sep 28, 2016 at 6:37 history edited André Fiedler CC BY-SA 3.0
added 81 characters in body
Sep 27, 2016 at 13:02 comment added Beat Christen Good point regarding clean up: The return false case is not taking care of it ;-)
Feb 2, 2014 at 18:36 review Suggested edits
Feb 2, 2014 at 18:38
Feb 2, 2014 at 18:32 review Suggested edits
Feb 2, 2014 at 18:34
Aug 30, 2013 at 8:11 history answered André Fiedler CC BY-SA 3.0