PHP uses the Glob function to implement a word delete all files under a directory,
Collected from online:
Copy the Code code as follows:
Array_map (' unlink ', glob (' * '));
A lot of friends may not know the function of Glob. Read the manual for more usage.
PHP Glob () function
Definition and usage
The Glob () function returns the file name or directory that matches the specified pattern.
The function returns an array that contains a matching file/directory. Returns False if an error occurs.
Grammar
Copy the Code code as follows:
Glob (Pattern,flags)
Parameters |
Description |
File |
Necessary. Specifies the retrieval mode. |
Size |
Optional. Specify a special setting.
- Glob_mark-Add a slash to each returned item
- Glob_nosort-Returns (not sorted) according to the original order in which the files appear in the directory
- Glob_nocheck-Returns the mode used for search if no file matches
- Glob_noescape-Backslash does not escape meta-characters
- Glob_brace-expand {a,b,c} to match ' A ', ' B ' or ' C '
- Glob_onlydir-Returns only catalog entries that match the pattern
- Glob_err-Stop and read error messages (such as unreadable directories), ignoring all errors by default
Note: Glob_err is added in PHP 5.1. |
Examples of Use
Example 1
Copy the Code code as follows: <?php
Print_r (Glob ("*.txt"));
?>
The output is similar to:
Copy the Code code as follows: Array
(
[0] = Target.txt
[1] = Source.txt
[2] = Test.txt
[3] = Test2.txt
)
Example 2
Copy the Code code as follows: <?php
Print_r (Glob ("* *"));
?>
The output is similar to:
Copy the Code code as follows: Array
(
[0] = Contacts.csv
[1] = default.php
[2] = Target.txt
[3] = Source.txt
[4] = Tem1.tmp
[5] = test.htm
[6] = Test.ini
[7] = test.php
[8] = Test.txt
[9] = Test2.txt
)
Ps: This is a magical function.
http://www.bkjia.com/PHPjc/844133.html www.bkjia.com true http://www.bkjia.com/PHPjc/844133.html techarticle PHP uses the Glob function to implement a word delete all files under a directory, collected from the online: Copy code code is as follows: Array_map (' unlink ', glob (' * '));