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

$dir='/tmp';

$files1=scandir($dir);

$files2=scandir($dir,1);

print_r($files1);

print_r($files2);

?>

以上例程的输出类似于:

Array

(

[0] => .

[1] => ..

[2] => bar.php

[3] => foo.txt

[4] => somedir

)

Array

(

[0] => somedir

[1] => foo.txt

[2] => bar.php

[3] => ..

[4] => .

)

类似与下=================

$dir="/tmp";

$dh=opendir($dir);

while (false!== ($filename=readdir($dh))) {

$files[] =$filename;

}

sort($files);

print_r($files);

rsort($files);

print_r($files);

?>

以上例程的输出类似于:

Array

(

[0] => .

[1] => ..

[2] => bar.php

[3] => foo.txt

[4] => somedir

)

Array

(

[0] => somedir

[1] => foo.txt

[2] => bar.php

[3] => ..

[4] => .

)

你可能感兴趣的:(scandir—列出指定路径中的文件和目录)