In my recurive function to zip a whole folders i have this piece of code glob($path. \'/*\') that give me all files and subfolders matching my $path.
Here I read
I am answering here in case anyone else is looking as this appears high on Google.
Solution 1 - glob only
This uses a glob that is tailored to skip '.' and '..' special directories. It matches anything that:
$globbed = glob("{*,.[!.]*,..?*}", GLOB_BRACE);
var_dump($globbed);
Solution 2 - globignore
This is a function to mimic the behaviour of globignore in bash.
function globignore(array $ignore, $glob, $glob_flags = 0)
{
$globbed = glob($glob, $glob_flags);
return array_filter($globbed, function ($f) use ($ignore)
{
$base = basename($f);
foreach($ignore as $i)
{
if ($i == $base) return false;
}
return true;
});
}
$globbed = globignore(['.','..'], "{*,.*}", GLOB_BRACE);
var_dump($globbed);
They appear to execute in almost exactly the same time on my system. Solution 1 requires less code but solution 2 is easier to include more terms to ignore.