-
- /*
- * Traverse the directory
- * fopen()
- * fread()
- * fclose()
- * @opendir(target path);E_WARNINE
- * readdir(directory reference handle) rewinddir ()
- * closedir()
- *
- * In programming, a handle is a special smart pointer. When an application wants to reference memory blocks or objects managed by other systems (such as databases, operating systems)
- *, handles are used. The difference between a handle and an ordinary pointer is that
- * The pointer contains the memory address of the referenced object, while the handle is a reference identifier managed by the system.
- * This identifier can be relocated to a memory address by the system. This mode of indirect object access enhances the system's control over the referenced object.
- * (Script Academy bbs.it-home.org)
- */
- $dirHandle=@opendir("phpMyAdmin") or die("Unsuccessful in opening the directory");
- echo "All the contents in the phpMyAdmin directory are: < br>";
- echo readdir($dirHandle)."
";
- echo readdir($dirHandle)."
";
-
- while(($file=readdir($dirHandle))!= =false)
- {
- $file="phpMyadmin".DIRECTORY_SEPARATOR.$file;
- if(is_dir($file))
- {
- echo "Directory: ".$file."
";
- }else
- {
- echo "File: ".$file."File size: ".filesize($file)."KB
";
- }
- }
- rewinddir($dirHandle); //Return to the beginning of the handle and traverse it again
- while(($file=readdir($dirHandle))!==false)
- {
- $file="phpMyadmin".DIRECTORY_SEPARATOR.$file;
- if($file!="."&&$file!=". .") //Do not read directly
- {
- if(is_dir($file))
- {
- echo "Directory: ".$file."
";
- }else
- {
- echo "File: ". $file."File size: ".filesize($file)."KB
";
- }
- }
- }
- closedir($dirHandle);
- ?>
Copy code
Example 2,
-
- /*
- * Traverse directory
- *
- * class dir{
- * string path;
- * resource handle;
- * string read(void);
- * void rewind(void);
- * void close(void);
- * }
- *
- * In programming, a handle is a special smart pointer. When an application wants to reference memory blocks or objects managed by other systems (such as databases, operating systems)
- *, handles are used. The difference between a handle and an ordinary pointer is that
- * The pointer contains the memory address of the referenced object, while the handle is a reference identifier managed by the system.
- * This identifier can be relocated to a memory address by the system. This mode of indirect object access enhances the system's control over the referenced object.
- *
- */
- $d = dir("phpMyAdmin");
- echo "The path is: ".$d->path."
";
- echo "The reference handle is: ".$d- >handle."
";
- // $d->read();
- // $d->read();
- while(($file=$d->read() )!==false)
- {
- if($file!="."&&$file!="..")
- {
- echo $file."
";
- }
- }
- $d- >close();
- ?>
Copy code
|