Traverse all files and subfolders under a folderRelated functions:1. Opendir (): function opens a directory handle that can be used by Closedir (), Readdir (), and Rewinddir ().If successful, the function returns a directory stream, otherwise it
The Opendir () function opens a directory handle that can be used by Closedir (), Readdir (), and Rewinddir (). If successful, the function returns a directory stream, otherwise it returns false and an error. You can hide the output of the error by
PHP Tutorial Lists all subfolders and file instances in the specified directory
function Listdirfiles ()
{
Set Directory
$dirs = './';
Declaring a folder array with an array of files$aFolders = Array ();$aFiles = Array ();
$ocfolder = Opendir
One: Directory operations
The first introduction is a function read from the directory, Opendir (), Readdir (), Closedir (), using the file handle is opened first, and then the iteration is listed:
Copy CodeThe code is as follows:
$base _dir =
BaseName ()
Returns the file name portion of the path
$path = "d:/lamp/apache2/htdocs/file.php";
Echo basename ($path). "";
Display filenames with file name extensions
Echo basename ($path, ' php ').";
Show filenames
Traverse the directory or traverse the specified type of files under the Directory, which is inevitable for every child shoes when writing programs. PHP itself also provides a lot of gray-often useful functions to use them correctly.The following is
function Listdirfiles (){Setting up a directory$dirs = './';
To declare an array of folders and files$aFolders = Array ();$aFiles = Array ();
$ocfolder = Opendir ($dirs);//The function returns a directory stream, otherwise it returns false and an
PHP closedir function
Closedir(PHP 4, PHP 5)
Closedir-Close Directory handle
Report Error descriptionInvalid Closedir ([resource $ dir_handle specified])Closes the directory stream dir_handle specified. The stream must have been opened Opendir ().
Header (' content-type:text/html;charset=utf-8; ');#目录操作函数详解1.GETCWD (OID): Returns False if the current directory is successfully returnedEcho ' 1.GETCWD (): ';Echo GETCWD ();2.chdir (): Function changes the current directory to the specified
Here are a few functions for you to reference.
Example one:
Copy Code code as follows:
function Deletedir ($dir) {
if (!handle= @opendir ($dir)) {//detect if the directory you want to open is present
Die ("No such catalogue");
}
This article illustrates the use of Readdir functions in PHP. Share to everyone for your reference. The specific usage analysis is as follows:
Definition and Usage: the Readdir () function returns an entry in a table of contents handle opened by
Traverse the directory or traverse the directory of the specified type of file, this is every child shoe in the writing program will inevitably use. PHP itself also provides a lot of gray useful functions, use them correctly, there is no mistake.The
Traverse the directory or traverse the directory of the specified type of file, this is every child shoe in the writing program will inevitably use. PHP itself also provides a lot of gray useful functions, use them correctly, there is no mistake.
We know that the temporary declarations of variables are stored in memory, even static variables, after the script is finished will be released, so, want to save the content of a variable for a long time, one way is to write to the file, put on the
The topics are as follows:Implement a single function of Linux under tree [only prints the number of directories and the number of files (no hidden files)]Preferred we introduce several related Linux system APIs
Name of function
Funny Summary of common PHP file operations functions the following is my summary of PHP file operation functions. Of course, this is only part of it. There are many other parts that I have not listed. 1. Resolution path: 1 get the file name:
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.