PHP  
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
search for in the  
<rewinddirDOM>
Last updated: Mon, 16 Jul 2012

scandir

(PHP 5)

scandir --  列出指定路径中的文件和目录

说明

array scandir ( string directory [, int sorting_order] )

返回一个 array,包含有 directory 中的文件和目录。如果 directory 不是一个目录,则返回布尔值 FALSE,并产生一条 E_WARNING 级别的错误。

默认情况下,返回值是按照字母顺序升序排列的。如果使用了可选参数 sorting_order(设为 1),则按照字母顺序降序排列。

例子 1. 简单的 scandir() 例子

<?php
$dir   
= '/tmp';
$files1 = scandir($dir);
$files2 = scandir($dir, 1);

print_r($files1);
print_r($files2);

/* Outputs something like:
Array
(
   [0] => .
   [1] => ..
   [2] => bar.php
   [3] => foo.txt
   [4] => somedir
)
Array
(
   [0] => somedir
   [1] => foo.txt
   [2] => bar.php
   [3] => ..
   [4] => .
)
*/
?>

例子 2. scandir() 在 PHP 4 中的实现

<?php
$dir
= "/tmp";
$dh  = opendir($dir);
while (
false !== ($filename = readdir($dh))) {
  
$files[] = $filename;
}

sort($files);

print_r($files);

rsort($files);

print_r($files);

/* Outputs something like:
Array
(
   [0] => .
   [1] => ..
   [2] => bar.php
   [3] => foo.txt
   [4] => somedir
)
Array
(
   [0] => somedir
   [1] => foo.txt
   [2] => bar.php
   [3] => ..
   [4] => .
)
*/
?>

参见 opendir()readdir()glob()is_dir()sort()




<rewinddirDOM>
 Last updated: Mon, 16 Jul 2012
 
Copyright © 2001-2005 The PHP Group
All rights reserved.
This unofficial mirror is operated at: http://manual.phpv.net/
Last updated: Thu Jul 7 19:13:47 2005 CST