Re: File handling
| From: | Kevin Waterson | Date: | Thu, 13 Feb 2003 10:35:47 +0000 |
| Subject: | Re: File handling | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-135403@lists.php.net to get a copy of this message | ||
This one time, at band camp,
Kenneth Suralta <ksuralta@ntsp.nec.co.jp> wrote:
> How do i delete all file in a directory???
bit ugly but...
function del_dir($dirname) {
$dh = opendir($dirname);
while(false !== ($file = readdir($dh)))
{
if($file != '.' && $file != '..')
{
$path = $dirname.'/'.$file;
if(is_dir($path))
{
del_dir($path);
}
else
{
@unlink($path);
}
}
}
if(@rmdir($dirname)==true)
{
echo $dirname.' deleted successfully<br />';
}
else
{
echo 'Unable to delete directory '.$dirname.'<br />';
}
}
if(file_exists($dirname))
{
del_dir($dirname);
}
else
{
echo 'Directory '.$dirname.' does not exist';
}
or something....
Kevin
--
______
(_____ \
_____) ) ____ ____ ____ ____
| ____/ / _ ) / _ | / ___) / _ )
| | ( (/ / ( ( | |( (___ ( (/ /
|_| \____) \_||_| \____) \____)
Kevin Waterson
Port Macquarie, Australia