PHP: Get all files and folders from a directory (folder)
Posted on 16. Jun, 2009 by Dragos in Coding, PHP
To get all files and folders from a directory (folder) I found scandir to be the perfect solution.
scandir scans a directory and returns an array containing all files and directories under the parent directory we’re looking in.
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';
$elements=scandir($lookin);
foreach($elements as $singleEl) {
if(is_dir($lookin.'/'.$singleEl)) rmdir($lookin.'/'.$singleEl);
else
unlink($lookin.'/'.$singleEl);
}
Translate this post
Related posts:
- Apache & ModRewrite: How to easily deny access to a folder with htaccess
- JavaScript: How to get the index (position within a group) of an object with jQuery?
- JavaScript: Where do I Find All Properties for All HTML Elements ?
- PHP: How to get creation time of file with PHP on Linux machines
- WordPress: Best SEO iTranslator for WordPress, get free traffic from fully automated plugin script
-
http://www.clockstyle.ru Wayne
-
Hakankara










































