Traverse the directory under the file name and show that we will use several functions one is the Opendir directory read function, and then use Readdir to get the directory in the information to the array and then through the while traversal.
Show all files in the directory
The code is as follows |
Copy Code |
$dir =dirname (__file__). " /.. /www.bkjia.c0m/";//Enter a different path here PHP iterates through all the files in the folder $handle =opendir ($dir. "."); Defines an array for storing file names $array _file = Array (); while (false!== ($file = Readdir ($handle))) { if ($file! = "." && $file! = "...") { $array _file[] = $file; Output file name } } Closedir ($handle); Print_r ($array _file); ?> |
Delete all files under the specified directory
The code is as follows |
Copy Code |
/** * Delete all files under the specified directory * * @param String $dir The path to be manipulated * Fit range, only for cases where subfolders are not present in the folder * Source DZ * Xiao Jia (www.bKjia.c0m) finishing in 2006-06-26 */ function Dir_clear ($dir) { $directory = Dir ($dir); Create a Dir class (as Bkjia.c0m's PHP manual says) to read every file in a directory while ($entry = $directory->read ()) {//loops each file and gets the file name $entry $filename = $dir. '/'. $entry; Gets the full file name, with the path of the if (Is_file ($filename)) {//If it is a file, perform the delete operation @unlink ($filename); } } $directory->close (); To close a class that reads a directory file Result (); }
|
http://www.bkjia.com/PHPjc/633115.html www.bkjia.com true http://www.bkjia.com/PHPjc/633115.html techarticle traverse the directory under the file name and show that we will use several functions one is the Opendir directory read function, and then use Readdir to get the directory in the information to the array and then through the while traversal. ...