当前位置:网站首页>PHP使用递归和非递归方式实现创建多级文件夹
PHP使用递归和非递归方式实现创建多级文件夹
2022-06-24 08:08:00 【BigChen_up】
项目需求:要求使用递归创建 AA/BB/CC/DD 文件夹; 代码实现如下:
function makeDir($dir) {
// 先判断上级目录是否存在,如果不存在,就创建上一级目录
$prev = dirname($dir);
if (!file_exists($prev)) {
// 创建上一级目录
makeDir($prev);
}
// 上一级目录创建成功了,就创建当前目录
mkdir($dir);
}
makeDir('AA/BB/CC/DD');
不使用递归的方法可以使用PHP自带的函数: mkdir(‘dir1/dir2/dir3’, 0777, true);
注意这种写法只支持PHP5.5以上版本
边栏推荐
- Ebanb B1 Bracelet brush firmware abnormal interrupt handling
- I heard that you are still spending money to buy ppt templates from the Internet?
- 2022-06-23: given a nonnegative array, select any number to make the maximum cumulative sum a multiple of 7, and return the maximum cumulative sum. N is larger, to the 5th power of 10. From meituan. 3
- 12、 Demonstration of all function realization effects
- 【LeetCode】415. String addition
- Ordinary people have no education background. Can they earn more than 10000 yuan a month by Self-taught programming?
- Lu Qi: I am most optimistic about these four major technology trends
- 普通人没有学历,自学编程可以月入过万吗?
- 零基础自学SQL课程 | 相关子查询
- When to use RDD and dataframe/dataset
猜你喜欢

Squid代理服务器应用

活动报名|Apache Pulsar x KubeSphere 在线 Meetup 火热报名中
![[e325: attention] VIM editing error](/img/58/1207dec27b3df7dde19d03e9195a53.png)
[e325: attention] VIM editing error

jupyter入门常见的几个坑:

The ambition of JD instant retailing from 618

EasyExcel单sheet页与多sheet页写出

【ES6闯关】Promise堪比原生的自定义封装(万字)

L01_ How is an SQL query executed?

Epidemic situation, unemployment, 2022, we shouted to lie down!

Leetcode -- wrong set
随机推荐
十二、所有功能实现效果演示
活动报名|Apache Pulsar x KubeSphere 在线 Meetup 火热报名中
PHP封装一个文件上传类(支持单文件多文件上传)
[Niuke] length of the last word of HJ1 string
Thinkphp5清除runtime下的cache缓存,temp缓存,log缓存
Target detection series fast r-cnn
Dynamic saving and recovery of FPU context under risc-v architecture
牛客网 十进制整数转十六进制字符串
[noi simulation] pendulum (linear algebra, Du Jiao sieve)
threejs辉光通道01(UnrealBloomPass && layers)
Groovy通过withCredentials获取Jenkins凭据
[ES6 breakthrough] promise is comparable to native custom encapsulation (10000 words)
Linux MySQL installation
Vidéo courte recommandée chaque semaine: Soyez sérieux en parlant de "métaunivers"
198. 打家劫舍
PhpStrom代码格式化设置
深入了解 border
Time Series Data Augmentation for Deep Learning: A Survey 之论文阅读
[e325: attention] VIM editing error
jupyter入门常见的几个坑: