You are here: Re: recursive delete all files/folders « PHP Programming Language « IT news, forums, messages
Re: recursive delete all files/folders

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация