note 56350 modified in function.directoryiterator-isfile by helly
| From: | helly@php.net | Date: | Tue, 01 Nov 2005 21:44:43 +0000 |
| Subject: | note 56350 modified in function.directoryiterator-isfile by helly | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-97946@lists.php.net to get a copy of this message | ||
Usage:
<?php
//open current directory
$dir = new DirectoryIterator(".");
// use do .. while since we need to iterate atleast once
// and the first two items are always "." and ".."
do {
// if it isn't "." or ".."
if (!$dir->isDot()) {
// echo out pathname and "/" if it's a directory
echo $dir->getPathname() . ($dir->isDir() ? "/" : "");
}
} while ($dir->next())
?>
Outputs something like:
/path/file1
/path/dir1/
/path/file2
/path/file3
/path/dir2/
---
Note from the extension author:
Try this:
<?php
foreach(new DirectoryIterator(".") as $file)
{
if (!$file->isDot()) {
echo $file->getPathname() . ($file->isDir() ? "/" : "");
}
}
?>
--was--
Usage:
<?php
//open current directory
$dir = new DirectoryIterator(".");
// use do .. while since we need to iterate atleast once
// and the first two items are always "." and ".."
do {
// if it isn't "." or ".."
if (!$dir->isDot()) {
// echo out pathname and "/" if it's a directory
echo $dir->getPathname() . ($dir->isDir() ? "/" : "");
}
} while ($dir->next())
?>
Outputs something like:
/path/file1
/path/dir1/
/path/file2
/path/file3
/path/dir2/
http://php.net/manual/en/function.directoryiterator-isfile.php