469,889 Members | 1,394 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,889 developers. It's quick & easy.

Negate glob() pattern

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 Gre,
Franz Marksteiner

Mar 16 '08 #1
2 2480
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:
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 Gre,
Franz Marksteiner
Mar 16 '08 #2
petersprc wrote:
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.
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?
On Mar 16, 5:31 pm, "Franz Marksteiner" <franzmarkstei...@gmail.com>
wrote:
>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 Gre,
Franz Marksteiner
--
Freundliche Gre,
Franz Marksteiner

Mar 17 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

15 posts views Thread by Georgy Pruss | last post: by
6 posts views Thread by Eric | last post: by
5 posts views Thread by Elbert Lev | last post: by
4 posts views Thread by Python Dunce | last post: by
6 posts views Thread by Hitesh | last post: by
2 posts views Thread by J | last post: by
3 posts views Thread by billiejoex | last post: by
5 posts views Thread by jo3c | last post: by
1 post views Thread by Waqarahmed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.