Connecting Tech Pros Worldwide Help | Site Map

Negate glob() pattern

  #1  
Old March 16th, 2008, 10:35 PM
Franz Marksteiner
Guest
 
Posts: n/a
Hi folks,

is there a way to negate a glob() pattern?
What I want is to get a tree structure, e.g. all .php files *and* all
directories.
How would I start here?

--
Freundliche Grüße,
Franz Marksteiner

  #2  
Old March 16th, 2008, 10:55 PM
petersprc
Guest
 
Posts: n/a

re: Negate glob() pattern


Hi,

The find command can search within a directory tree:

$dir = dirname(__FILE__);
$cmd = 'find ' . escapeshellarg($dir) . ' -name "*.php" ' .
'-o -type d 2>&1';
exec($cmd, $output, $exitCode);
if ($exitCode != 0) {
throw new Exception("Command \"$cmd\" failed with " .
"exit code $exitCode: " . join("\n", $output));
}
echo "Found " . count($output) . " entries.<br>\n";

As for glob, you can just call it multiple times: once with *.php and
once with the GLOB_ONLYDIR flag.

You could also use opendir/readdir.

On Mar 16, 5:31 pm, "Franz Marksteiner" <franzmarkstei...@gmail.com>
wrote:
Quote:
Hi folks,
>
is there a way to negate a glob() pattern?
What I want is to get a tree structure, e.g. all .php files *and* all
directories.
How would I start here?
>
--
Freundliche Grüße,
Franz Marksteiner
  #3  
Old March 17th, 2008, 10:25 AM
Franz Marksteiner
Guest
 
Posts: n/a

re: Negate glob() pattern


petersprc wrote:
Quote:
As for glob, you can just call it multiple times: once with *.php and
once with the GLOB_ONLYDIR flag.
Yeah, I guess that makes sense.
Quote:
You could also use opendir/readdir.
The thing is that glob seems to be way easier with the pattern
functionality.
In the past I did use opendir.

What would you prefer?
Quote:
On Mar 16, 5:31 pm, "Franz Marksteiner" <franzmarkstei...@gmail.com>
wrote:
Quote:
>Hi folks,
>>
>is there a way to negate a glob() pattern?
>What I want is to get a tree structure, e.g. all .php files *and* all
>directories.
>How would I start here?
>>
>--
>Freundliche Grüße,
>Franz Marksteiner
--
Freundliche Grüße,
Franz Marksteiner

Closed Thread