| Article: |
Working with Files in PHP, Part 3 | |
| Subject: | dir class | |
| Date: | 2003-02-06 12:31:15 | |
| From: | arjo.post@hccnet.nl | |
|
the following object creation is not working for me: $mydir = new dir('/path/to/mydir'); I get the error: Fatal error: Cannot instantiate non-existent class: dir in d:\myphp\dir.php on line 2 can you help me?
|
||
Showing messages 1 through 4 of 4.
-
dir class
2003-11-19 12:28:21 anonymous2 [Reply | View]
BTW, the if(is_dir($mydir->path.$file)) part includes the .. and . "directories"... so if, like me, you just wish to display a list of sub-directories, you'll need to ignore those two entries:
if(is_dir($mydir->path.$file) && !strstr($file,".")) {
Great article BTW :-) -
dir class
2005-02-09 11:43:32 poboxbot [Reply | View]
Careful. Using strstr here will exclude all directories with a '.' character *anywhere* in its name.
So while it will exclude "." and "..", it will also exclude "images.web" or "photos.icons" or whatever.
Use preg_match instead:
if(is_dir($path) && !preg_match("#^\.+#", $file))






from:
$mydir = new dir('/path/to/mydir');
to:
$mydir = dir('/path/to/mydir');