Syntax
Opendir (path, context)
*/
$ D = dir ("c: windows"); // open the directory and assign the value to the variable
Echo "handle:". $ d-> handle. "n"; // handel attribute of the output Directory
Echo "<p> ";
Echo "path:". $ d-> path. "n"; // path attribute of the output Directory
Echo "<p> ";
While (false! ==( $ Entry = $ d-> read () // read the object through a loop
{
Echo $ entry. "n ";
}
$ D-> close (); // close the directory handle
//
$ Dir = "c: windows"; // define a directory
If (is_dir ($ dir) // if the variable is a directory
{
If ($ dh = opendir ($ dir); // if the directory is successfully opened
{
Echo "directory". $ dir. "opened successfully ";
}
}
Echo "<br> ";
Closedir ($ dh); // Close The OpenEd directory handle
Echo "directory". $ dir. "disabled! ";
///
$ Dir = "c: windows"; // defines directory variables
If (is_dir ($ dir) // determines whether the variable is a directory.
{
If ($ dh = opendir ($ dir) // You can check whether the directory is successfully opened.
{
While ($ file = readdir ($ dh ))! = False) // read the file information in the directory cyclically
{
Echo "filename: $ file, filetype:". filetype ($ dir. $ file). "n"; // output file name and file type
}
Closedir ($ dh); // Close the directory handle
}
}
///
If ($ handle = opendir ('web') // if the directory is successfully opened
{
While (false! ==( $ File = readdir ($ handle) // read entries in the directory cyclically
{
If ($ file! = "." & $ File! = "...") // If the file is not the current or upper-level Directory
{
Echo "$ filen"; // name of the output file
}
}
Closedir ($ handle); // Close the directory handle
}
//
If ($ handle = opendir ('08') // if the directory is successfully opened
{
While (false! ==( $ File = readdir ($ handle) // read entries in the directory cyclically
{
If ($ file! = "." & $ File! = "...") // If the file is not the current or upper-level Directory
{
Echo "$ filen"; // name of the output file
}
}
Rewind ($ handle); // returns the directory handle.
If (readdir ($ handle) // You can check whether the result is returned successfully.
{
Echo "reverse success ";
}
Else
{
Echo "failed to return ";
}
Closedir ($ handle); // Close the directory handle
}
// If you want to sort directories by letters, for example
$ Files1 = scandir ($ dir); // list content in alphabetical order to an array
$ Files2 = scandir ($ dir, 1); // list content in alphabetical order to an array