PHP clears (deletes) the file under the specified directory, does not delete the Directory folder implementation code,
In web development, we may encounter the need to empty all files in a directory, but not delete subdirectories in this directory (and certainly not delete
Here's The program code:
The code is as follows
Copy Code
function Mkdirs ($dir){if (!is_dir ($dir)){if (!mkdirs (DirName ($dir)) {return false;}if (!mkdir ($dir, 0777)) {return false;}}return true;}Mkdirs (' div/css/layout ');
In the same vein, PHP uses RmDir and unlink to recursively delete the multilevel
The project needs to write a function that traverses all the files in the specified directory, and the subdirectories in that directory are traversed. Output The property information of the file and store it.
Think of the need, is not a ls-al command, to achieve the relevant properties of the good, plus a traversal OK.
In the process of the project, it is easy to manipulate, using JSON format storage, but
Copy the Code code as follows:
function List_files ($dir){if (Is_dir ($dir)){if ($handle = Opendir ($dir)){while (($file = Readdir ($handle))!== false){if ($file! = "." $file! = ":" $file! = "Thumbs.db"){Echo '. $file. ''." \ n ";}}Closedir ($handle);}}}
Here is an excerpt from the article published before this site. More tips can be used for reference.
21 useful and convenient PHP function codes colle
Requirements: Delete files, directory structure: ip/year/month, everyone has a copy of this directory now need to delete all files before 2012, 2012 after the deletion of a specific month.Originally wanted to use find, the results found that these file time (A,M,C) records are not originally generated.No way to have to think of a soil method to traverse, who has a good method, welcome to inform.
Cop
The approximate program idea is to use the recursive rules to calculate the amount of space occupied by the directory, and then the value of the space to write into the text file, so long as the access to the TXT file will know how much space occupied, do not have to read the disk frequently, save resources. Each time a user uploads a file or deletes a file, it is re-counted. Of course, you can also save the statistical results in the database.
Copy
This article will explain in detail how these functions are used. First, we describe the listing file functionality for the dir command in the Python language similar to the Windows system, and then describe how to test whether a file name corresponds to a standard file, directory, or link, and how to extract the file size and date. After that, we'll also show you how to delete files and directories, how to copy and delete files, and how to break down
Objective
In the previous article we described how to configure the Go development environment under Windows installation. This article describes the directory structure of code Golang, application compilation, custom packages, and references to remote packages.
Code directory structure
At the end of the Gopath we set
Although this code is short, but very useful, it can easily establish the directory you specified in the specified suffix file hyperlink, and can be set, will not be the specified directory home page navigation.
function NavBar () {
$files = Dir ("."); Specify directory
This code is short, but very practical, it can easily create the directory you specify the name of the specified suffix file hyperlink, and can be set, will not be the specified directory first navigation.
function NavBar () {
$files = Dir ("."); Specify directory
$pipe = "
The Linux kernel source code directory is as follows:/arch: The directory includes all the core code related to the architecture. Each of the subdirectories below represents a Linux-supported architecture, such as i386, a subdirectory of the Intel CPU and its compatible architecture. PC machines are generally based on
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");
}
while (False!== ($file =readdir ($handle))) {
if ($file!== "." $file!== "...") {//Exclude current
This code is short, but very practical, it can easily create the directory you specify the name of the specified suffix file hyperlink, and can be set, will not be the specified directory first navigation.
function NavBar () {
$files = Dir ("."); Specify directory
$pipe = "
We all know that the actual development of the code contains a lot of files, if all the files are placed in the same directory, it is basically a mess, maintenance is very troublesome and arduous, dizziness and brain swelling. Below, I draw a picture to look at the picture according to own actual experience:
Many times, the Third_part and comm in the circle can be placed in the application
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.