Delete All Files In a Directory In a Loop using php

by satheeshkumar 2012-08-06 16:40:50

Delete All Files In a Directory In a Loop using php,

In order to use the PHP rmdir() function which removes a directory folder, that target folder must be empty in order for the folder to be deleted. So first we have to delete all files that are inside of it. Or you might just require a script that will empty a folder of its files on occasion.


$dir = "myFolder/";
$files = opendir($dir);
while ($file = readdir($files))
{
if(!is_dir($file))
{
unlink ("$dir"."$file");
}
}
closedir($files);
?>

Tagged in:

859
like
0
dislike
0
mail
flag

You must LOGIN to add comments