欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

php如何遍历文件目录的方法教程

程序员文章站 2022-04-09 14:13:33
...
在我们日常开发工作中,经常会遇到遍历文件目录的情况,相信大家也知道对于遍历文件目录的有很多种,PHP本身也提供了很多有用的函数,如果目录很多,大家都会用队列方式,但是我们今天给大家介绍的是php遍历文件目录的类使用!

第一步:

下载我们本次需要使用的phpphp遍历文件目录的类:http://www.php.cn/xiazai/leiku/823

第二步:

把下载的文件解压都本地,然后实例化类:

1.获取目录列表:

<?php
$Dir_dir  = './example';

$getDirFile = new getDirFile();
$getDir = $getDirFile->getDir( $Dir_dir );

print_r($getDir);
?>

结果:

php如何遍历文件目录的方法教程

2.获取文件列表

<?php
$File_one_dir = './example/example_one';
$File_two_dir = 'E:/Workspace/mycode/getDirFile/example/example_two';

$getDirFile = new getDirFile();
$getFile_one = $getDirFile->getFile( $File_one_dir );
$getFile_two = $getDirFile->getFile( $File_two_dir );

print_r($getFile_one);
print_r($getFile_two);
?>

结果显示:

php如何遍历文件目录的方法教程

3.获取目录/文件列表

<?php
$Dir_dir  = './example';

$getDirFile = new getDirFile();
$getDirFile  = $getDirFile->getDirFile( $Dir_dir );

print_r($getDirFile);
?>

结果显示:

php如何遍历文件目录的方法教程

以上就是php如何遍历文件目录的方法教程的详细内容,更多请关注其它相关文章!

相关标签: php 方法 目录