readdir
(PHP 3, PHP 4 , PHP 5)
readdir -- 從目錄 handle 中讀取資料
Description
string
readdir ( int dir_handle)
傳回目錄中下一個檔案的檔名。 注意檔案名稱不會跟次序傳回。
示範 1.List all files in the current directory
<?php $handle=opendir('.'); echo "Directory handle: $handle\n"; echo "Files:\n"; while (($file = readdir($handle))!==false) { echo "$file\n"; } closedir($handle); ?>
|
|
注意 readdir() 也會傳回 . 和
.. 兩個名稱(分別代表目前目錄和父目錄。 如你不想要把它們過瀘掉就好了。像這漾:
示範 2.
List all files in the current directory and strip out . and
..
<?php $handle=opendir('.'); while (false!==($file = readdir($handle))) { if ($file != "." && $file != "..") { echo "$file\n"; } } closedir($handle); ?>
|
|