473,508 Members | 3,235 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 Grüße,
Franz Marksteiner

Mar 16 '08 #1
2 2674
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 Grüße,
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 Grüße,
Franz Marksteiner
--
Freundliche Grüße,
Franz Marksteiner

Mar 17 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
3058
by: Georgy Pruss | last post by:
On Windows XP glob.glob doesn't work properly for files without extensions. E.g. C:\Temp contains 4 files: 2 with extensions, 2 without. C:\Temp>dir /b * aaaaa.aaa bbbbb.bbb ccccc ddddd ...
6
1486
by: Eric | last post by:
Pythonistas, I seem at a loss for a List Comprehension syntax that will do what I want. I have a list of string position spans: >>> breaks the first pair representing: someString
5
2317
by: Elbert Lev | last post by:
#Here is the script #Python 2.3 on W2K import glob name = glob.glob(u"./*.mp3") print type(name) name = glob.glob(u"*.mp3") print type(name)
4
3420
by: Python Dunce | last post by:
I've run into an issue with glob and matching filenames with brackets '' in them. The problem comes when I'm using part of such a filename as the path I'm passing to glob. Here's a trimmed down...
6
3281
by: Hitesh | last post by:
import string import os f = open ("c:\\servername.txt", 'r') linelist = f.read() lineLog = string.split(linelist, '\n') lineLog = lineLog #print lineLog for l in lineLog:
2
1384
by: J | last post by:
Greetings Group- I'm trying to put together a pattern matching script that scans a directory tree for tif images contained in similar folder names, but running into a NewB problem already. Is it...
8
2355
by: mark.bergman | last post by:
I am porting from Digital Unix to Linux (RHEL 4), and am seeing a difference in the return value of glob(). Given a non-existant directory "/tmp/a", and the following line of code: result =...
3
1899
by: billiejoex | last post by:
os.listdir(path) return a list of file names independently if the path- argument used is absolute or relative: '/home/user' glob.glob, instead, return file names only if given path is...
5
2391
by: jo3c | last post by:
hi everyone happy new year! im a newbie to python i have a question by using linecache and glob how do i read a specific line from a file in a batch and then insert it into database? because...
0
7128
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7332
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7393
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7058
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
4715
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3206
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3191
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
769
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
426
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.