|
Posted by Alexey Kulentsov on 10/07/05 11:13
betterdie@gmail.com wrote:
> Dear guru
>
> I want to delete all file and folder recursivly under php code, can
> anyone give me commend for this.
/// Clean directory
/** Delete all files in directory
* @param $path directory to clean
* @param $recursive delete files in subdirs
* @param $delDirs delete subdirs
* @param $delRoot delete root directory
* @access public
* @return success
*/
function cleanDir($path,$recursive=true,$delDirs=false,$delRoot=null)
{
$result=true;
if($delRoot===null) $delRoot=$delDirs;
if(!$dir=@dir($path)) return false;
while($file=$dir->read())
{
if($file==='.' || $file==='..') continue;
$full=$dir->path.DIRECTORY_SEPARATOR.$file;
if(is_dir($full) && $recursive)
{
$result&=filesys::cleanDir($full,$recursive,$delDirs,$delDirs);
}else if(is_file($full))
{
$result&=unlink($full);
}
}
$dir->close();
if($delRoot)
{
$result&=rmdir($dir->path);
}
return $result;
}
Navigation:
[Reply to this message]
|