Skip to content

Instantly share code, notes, and snippets.

@mistic100
Last active January 7, 2021 14:33
Show Gist options
  • Save mistic100/8356949 to your computer and use it in GitHub Desktop.
Save mistic100/8356949 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