search
Homephp教程php手册php对文件夹进行相关操作(遍历、计算大小)

这篇文章主要介绍了php对文件夹进行相关操作,包括遍历并打印指定目录下所有文件和计算文件大小去空白,以及去重复值等,感兴趣的小伙伴们可以参考一下

为大家分享的第一个操作内容: 遍历并打印指定目录下所有文件

0&&--$flag) //负数仍为真 echo ' '; if(is_dir($dir_name.$filename)) //判断 是否为一个目录 { echo ''."".$filename."
"; scan_dir($dir_name.$filename.'http://www.jb51.net/',$dir_flag+1); //$dir_flag标志目录树层次 } else { echo "".$filename."
"; } } } closedir($dir_handle); //关闭目录句柄 echo "文件总数:".$FILE_COUNT.'
'; } scan_dir('D:/AppServ/www/mytest/shopping/payment/'); /*总结: 1,关于路径 目录的路径末尾都加上 'http://www.jb51.net/' 以便后面与文件名字符串连接 形成新的 路径字符串 2,目录遍历 这是一个关于树的问题 3,is_dir()函数第一个参数必须是一个能够识别的PATH否则会因目录不存在而返回一个false容易误解 得出 “这不是一个目录”的错误结论 形成逻辑上的错误 4,注意当前路径'.'和上一级路径'..'的剔除 否则 在递归环节造成死循环 直至内存耗尽出错。 5,dir_flag这个变量是记录树的深度 以便于目录分级分层输出 */ /*不足 1,输出排版不完善 2,逻辑与表示层混乱 不分明 大忌! 3,面向过程 */

#####单目录#####

// 列出目录内容 $dir 不要加 'http://www.jb51.net/' 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); } } } list_files('D:/AppServ/www/mytest/shopping/payment');

PHP 对文件进行的第二个操作内容:获得文件夹大小 计算文件

以上就是关于php对文件夹的进行的基本操作,希望对大家的学习有所帮助。

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),