This article mainly and everyone to share the PHP directory function use method, hope to help everyone.
Create a Directory
1. mkdir: Try creating a new directory specified by pathname.
BOOL MkDir (string $pathname [, int $mode = 0777 [, bool $recursive = False [, resource $context]])
Tip: The second one is ignored in Windows and useful in Linux!
Delete Directory
2. RmDir: Try to delete the directory specified by DirName. The directory must be empty and have the appropriate permissions. Failure results in a e_warning level error.
BOOL RmDir (String $dirname [, Resource $context])
Tip: Do not allow deletion of non-empty directories
Get directory Contents
Opendir: Opens a directory handle that can be used for subsequent closedir (), Readdir (), and Rewinddir () calls.
Resource Opendir (String $path [, Resource $context])
Return value: Returns the resource of the directory handle if successful, and FALSE if it fails.
Readdir: Returns the file name of the next file in the directory. The file name is returned as a sort in the file system.
String Readdir ([resource $dir _handle])
Parameter $dir_handle
: Resource of the directory handle, previously opened by Opendir ()
Return value: Success returns the file name or FALSE on failure
With a handle, read a file (including files and subdirectories) from the directory, read one file at a time, and move the file pointer down!
Note that the virtual directory exists under each directory .
..
. Represents the current directory, and the parent directory.
With the loop structure, you can get the entire contents of the directory:
It is common to ignore .
and ..
0 file names may be treated as false, so you need to use the all-unequal comparison operator to handle
Closedir: Closes the directory stream specified by Dir_handle. The stream must be opened previously by Opendir ().
void Closedir ([resource $dir _handle])
Rename: rename (move) a file or directory and rename the oldname to NewName.
BOOL Rename (string $oldname, String $newname [, Resource $context])
Create a Directory
1. mkdir: Try creating a new directory specified by pathname.
BOOL MkDir (string $pathname [, int $mode = 0777 [, bool $recursive = False [, resource $context]])
Tip: The second one is ignored in Windows and useful in Linux!
Delete Directory
2. RmDir: Try to delete the directory specified by DirName. The directory must be empty and have the appropriate permissions. Failure results in a e_warning level error.
BOOL RmDir (String $dirname [, Resource $context])
Tip: Do not allow deletion of non-empty directories
Get directory Contents
Opendir: Opens a directory handle that can be used for subsequent closedir (), Readdir (), and Rewinddir () calls.
Resource Opendir (String $path [, Resource $context])
Return value: Returns the resource of the directory handle if successful, and FALSE if it fails.
Readdir: Returns the file name of the next file in the directory. The file name is returned as a sort in the file system.
String Readdir ([resource $dir _handle])
Parameter $dir_handle
: Resource of the directory handle, previously opened by Opendir ()
Return value: Success returns the file name or FALSE on failure
With a handle, read a file (including files and subdirectories) from the directory, read one file at a time, and move the file pointer down!
Note that the virtual directory exists under each directory .
..
. Represents the current directory, and the parent directory.
With the loop structure, you can get the entire contents of the directory:
It is common to ignore .
and ..
0 file names may be treated as false, so you need to use the all-unequal comparison operator to handle
Closedir: Closes the directory stream specified by Dir_handle. The stream must be opened previously by Opendir ().
void Closedir ([resource $dir _handle])
Rename: rename (move) a file or directory and rename the oldname to NewName.
BOOL Rename (string $oldname, String $newname [, Resource $context])