Last active
January 7, 2021 14:33
-
-
Save mistic100/8356949 to your computer and use it in GitHub Desktop.
[PHP] Check if a folder is empty
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Check if a directory is empty (a directory with just '.svn' or '.git' is empty) | |
* | |
* @param string $dirname | |
* @return bool | |
*/ | |
function dir_is_empty($dirname) | |
{ | |
if (!is_dir($dirname)) return false; | |
foreach (scandir($dirname) as $file) | |
{ | |
if (!in_array($file, array('.','..','.svn','.git'))) return false; | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment