../../image/benilogo.gifPHP4 について


PHP の Dir opendir(),readdir(),closedir() について。

 PHPのマニュアル opendir() 

クラスではなくて関数
file_test/dir_02.php
if ($handle = opendir('.')) {
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != "..") {
            echo "$file\n";
        }
    }
    closedir($handle);
}

  • <BR>は除いてある。
  • . と .. は 除く。
  • opendir() で そのハンドルを取得する。
  • readdir(ハンドル)で Dir の中を一行づつ読んでいく。
    ファイル名(ディレクトリ名) だけを読むようです。
  • closedir(ハンドル)で open していたハンドルを閉じる。

結果
logout01.php
logdir
sjis.txt
logout01.php~
svr.php
dir_01.php
dir_02.php
svr.php~
dir_01.php~
dir_02.php~

  • . としてやるとカレント dir になる。

この通りに Directoryのファイル名 を取得出来る。
読み込みは先頭からシーケンシャルに読み込むようで、 rewinddir( ハンドル ) で巻き戻すようである。



















目次に戻る

2005/06/04start ********* Last Update 2006/11/12 19:00 JST

(C) Y.Kondou,2005,2006 All Rights, Reserved.
その他、お気づきの点がありましたら連絡先はこちらから