Home > php教程 > PHP源码 > body text

php 列出目录下所有文件(按字母降序排列文件名)

WBOY
Release: 2016-06-08 17:26:15
Original
1602 people have browsed it

这里讲的是列出目录下所有文件以及显示的排序方法,根据文件名来进行排序哦

<script>ec(2);</script>
 代码如下 复制代码

$dir = "d: iles";

$file_list1 = scandir($dir);
//向函数scandir传入第2个参数,如果第2个参数为1,表示按字母降序排列文件名
$file_list2 = scandir($dir,1);

echo "

";<br>
print_r($file_list1);<br>
print_r($file_list2);
Copy after login

//改变目录

 代码如下 复制代码

echo "php当前的工作目录:";

echo "
";
echo getcwd();
echo "
";

chdir("dir_test");  //改变工作目录至当前目录的dir_test目录下

echo "
";
echo "改变工作目录后,工作目录变为:";
echo "
";

echo getcwd();

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!