在php中有很多方法来把目录所有文件列出的代码,如下:
-
-
- $list = scandir(".");
- $zipname = "";
- foreach($list as $file)
- {
- if($file=="."||$file=="..")continue;
- $b=substr($file,-3);
- if($b==".gz"||$b==".fz")
- { $zipname = $file; break; }
- }
-
-
-
- $d=dir(".");
- echo $d->path.$e;
- while(false !== ($e= $d->read())) {
- echo "<a href=$e target=_blank >$e</a>"."<br>";
- }
- $d->close();
-
-
-
-
- $dirs = array();
- foreach(glob("test/*") as $d)
- {
- if(is_dir($d))
- {
- $dirs[] = $d;
- }
- }
- print_r($dirs);
-
-
-
- glob("test/*", glob_onlydir) ;
-
-
-
- function clean_dir($path) {
- if (!is_dir($path)) {
- if (is_file($path)) {
- unlink($path);
- }
- return;
- }
- $p=opendir($path);
- while ($f=readdir($p)) {
- if ($f=="." || $f=="..") continue;
- clean_dir($path.$f);
- }
- rmdir($path);
- return;
- }
|