PHP: Get all files and folders from a directory (folder) PHP的:获取所有从一个目录(文件夹的文件和文件夹)
Posted on 16.发布16。 Jun, 2009 by Dragos in Coding , PHP 2008年6月,2009年在编码 ,PHP的 德拉戈什
To get all files and folders from a directory (folder) I found scandir to be the perfect solution.让所有从一个目录(文件夹),我发现的scandir是完美的解决方案文件和文件夹。
scandir scans a directory and returns an array containing all files and directories under the parent directory we're looking in. 的scandir扫描一个目录,并返回一个数组,包含父目录下的所有文件和目录,我们正在寻找英寸
The code below will try to remove a directory, if the element is a directory or delete a file, if respectively the element is a file.下面的代码会尝试删除一个目录,如果元素是一个目录或删除文件,如果分别元素是一个文件。
$lookin='./home/folder'; $ lookin ='。/家/文件夹'; $elements=scandir($lookin); $元素=的scandir($ lookin); foreach($elements as $singleEl) { Foreach源($元素$ singleEl)( if(is_dir($lookin.'/'.$singleEl)) rmdir($lookin.'/'.$singleEl);如果(is_dir($ lookin .'/'.$ singleEl))下创建($ lookin .'/'.$ singleEl); else其他的 unlink($lookin.'/'.$singleEl);断开($ lookin .'/'.$ singleEl); } )
Translate this post翻译这个职位
Related posts:相关岗位:
- Apache & ModRewrite: How to easily deny access to a folder with htaccess 阿帕奇&ModRewrite:如何轻松拒绝访问与htaccess的文件夹
- JavaScript: How to get the index (position within a group) of an object with jQuery? JavaScript的:如何获取指数(位置在一组与jQuery对象)?
- JavaScript: Where do I Find All Properties for All HTML Elements ? JavaScript的:我在哪里可以找到所有HTML元素所有属性?
- PHP: How to get creation time of file with PHP on Linux machines PHP:如何获得Linux的机器用PHP创建文件时间
- Wordpress: Best SEO iTranslator for Wordpress, get free traffic from fully automated plugin script WordPress的:最佳WordPress的搜索引擎iTranslator,从全自动插件脚本免费交通












































