这篇文章主要介绍了php最简单的删除目录与文件实现方法,只需要两行代码即可实现删除目录与文件的功能,是非常实用的技巧,需要的朋友可以参考下
本文实例讲述了php最简单的删除目录与文件实现方法。分享给大家供大家参考。
具体实现代码如下:
复制代码 代码如下:
//删除目录下所有空目录
array_map('rmdir', glob('*', GLOB_ONLYDIR));
//删除目录所有文件
array_map('unlink', array_filter(glob('*'), 'is_file'));
?>
原理分析:array_map('rmdir', glob('*', GLOB_ONLYDIR));
删除简单是使用了array_map函数,它的作用是返回用户自定义函数作用后的数组,回调函数接受的参数数目应该和传递给 array_map() 函数的数组数目一致,而glob是遍历目录,然后把返回数组给了rmdir进行目录删除,然后:
复制代码 代码如下:
array_map('unlink', array_filter(glob('*'), 'is_file'));
原理差不多了,就是遍历目录之后我们再删除指定目录中的文件即可.
希望本文所述对大家的PHP程序设计有所帮助。
,
Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 English version
Recommended: Win version, supports code prompts!

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool