Skip to content

Instantly share code, notes, and snippets.

@useless-stuff
Created February 20, 2016 08:09
Show Gist options
  • Save useless-stuff/e801e4b15430adb81e20 to your computer and use it in GitHub Desktop.
Save useless-stuff/e801e4b15430adb81e20 to your computer and use it in GitHub Desktop.
PHP - DirectoryIterator
<?php
$filePath = '/vagrant/data/anniballo.com';
/**
* Class FolderFilter
*/
class FolderFilter extends FilterIterator
{
/**
* @return bool
*/
public function accept()
{
return ($this->getInnerIterator()->isDir() && !$this->getInnerIterator()->isDot());
}
}
$filter = new FolderFilter(new DirectoryIterator($filePath));
foreach ($filter as $key => $value) {
echo $filter->getBasename().PHP_EOL;
}
// Output:
/*
log
wp-admin
wp-content
wp-includes
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment