Skip to content

Instantly share code, notes, and snippets.

@antelove19
Forked from mistic100/dir_is_empty.php
Created September 2, 2018 10:01
Show Gist options
  • Save antelove19/52cc61d3b516df25eec23a6aed3c8af1 to your computer and use it in GitHub Desktop.
Save antelove19/52cc61d3b516df25eec23a6aed3c8af1 to your computer and use it in GitHub Desktop.
[PHP] Check if a folder is empty
<?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