Hướng dẫn php directoryiterator - thư mục php

Krystianmularchot tại Gmail Dot Com ¶

13 năm trước

Shows us all files and catalogues in directory except "." and "..".

foreach (new DirectoryIterator('../moodle') as $fileInfo) {
    if(
$fileInfo->isDot()) continue;
    echo
$fileInfo->getFilename() . "
\n"
;
}
?>

Alvaro tại demogracia dot com

5 năm trước

DirectoryIterator is just an lightweight SplFileInfo iterator and its methods operate on whatever item the internal cursor points to. In other words:

$iterator = new DirectoryIterator('C:\\');
echo
$iterator->getPathname();
?>

... will NOT print "C:\" but the path of the first file or subdirectory retrieved, e.g. "C:\$Recycle.Bin".

Rogier tại DSesone Dot NL ¶

10 năm trước

Beware of the behavior when using FilesystemIterator::UNIX_PATHS, it's not applied as you might expect.

I guess this flag is added especially for use on windows.
However, the path you construct the RecursiveDirectoryIterator or FilesystemIterator with will not be available as a unix path.
I can't say this is a bug, since most methods are just purely inherited from DirectoryIterator.

In my test, I'd expected a complete unix path. Unfortunately... not quite as expected:

         // say $folder = C:\projects\lang$flags = FilesystemIterator::KEY_AS_PATHNAME | FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::SKIP_DOTS | FilesystemIterator::UNIX_PATHS;
       
$d_iterator = new RecursiveDirectoryIterator($folder, $flags);

foreach (new DirectoryIterator('../moodle') as $fileInfo) {
    if(
$fileInfo->isDot()) continue;
    echo
$fileInfo->getFilename() . "
\n"
;
}
?>
0

foreach (new DirectoryIterator('../moodle') as $fileInfo) {
    if(
$fileInfo->isDot()) continue;
    echo
$fileInfo->getFilename() . "
\n"
;
}
?>
1

David Lanstein ¶

13 năm trước

foreach (new DirectoryIterator('../moodle') as $fileInfo) {
    if(
$fileInfo->isDot()) continue;
    echo
$fileInfo->getFilename() . "
\n"
;
}
?>
2

foreach (new DirectoryIterator('../moodle') as $fileInfo) {
    if(
$fileInfo->isDot()) continue;
    echo
$fileInfo->getFilename() . "
\n"
;
}
?>
3

foreach (new DirectoryIterator('../moodle') as $fileInfo) {
    if(
$fileInfo->isDot()) continue;
    echo
$fileInfo->getFilename() . "
\n"
;
}
?>
4

foreach (new DirectoryIterator('../moodle') as $fileInfo) {
    if(
$fileInfo->isDot()) continue;
    echo
$fileInfo->getFilename() . "
\n"
;
}
?>
5

foreach (new DirectoryIterator('../moodle') as $fileInfo) {
    if(
$fileInfo->isDot()) continue;
    echo
$fileInfo->getFilename() . "
\n"
;
}
?>
6

Alvaro tại demogracia dot com

5 năm trước

foreach (new DirectoryIterator('../moodle') as $fileInfo) {
    if(
$fileInfo->isDot()) continue;
    echo
$fileInfo->getFilename() . "
\n"
;
}
?>
7

Rogier tại DSesone Dot NL ¶

10 năm trước

foreach (new DirectoryIterator('../moodle') as $fileInfo) {
    if(
$fileInfo->isDot()) continue;
    echo
$fileInfo->getFilename() . "
\n"
;
}
?>
8

David Lanstein ¶

Mark Van Straten ¶

foreach (new DirectoryIterator('../moodle') as $fileInfo) {
    if(
$fileInfo->isDot()) continue;
    echo
$fileInfo->getFilename() . "
\n"
;
}
?>
9

0

1

2

14 năm trước

Kunal Bhatia-> kmasterzone@gmail dot com ¶

3

4