The code is as follows: |
Copy code |
$ Dir = "d: www.111cn.net "; // Open the directory $ dir and assign the directory handle to the variable $ dh If ($ dh = opendir ($ dir )) { // Get the file name through the while loop using the readdir function While ($ file_name = readdir ($ dh ))! = False) { Echo "file name:". $ file_name; Echo "<br/> "; Echo "<br/> "; } // After processing is complete, close the directory handle $ dh Closedir ($ dh ); } |
/*
Opendir definition and usage
The opendir () function opens a directory handle, which can be used by closedir (), readdir (), and rewinddir.
If the operation succeeds, the function returns a directory stream. Otherwise, false and an error are returned. You can add "@" before the function name to hide the error output.
Syntax
Opendir (path, context)
Readdir definition and usage
The readdir () function returns the entries in the directory handle opened by opendir.
If the call succeeds, the function returns a file name; otherwise, false.
Syntax
Readdir (dir_stream)
The closedir () function disables the directory handle opened by the opendir () function.
Syntax
Closedir (dir_stream)