Hi,
Here is what I am using. I think I got from PHP.net comments:
function deleteDirectory($dirname,$only_empty=false) {
if (!is_dir($dirname))
return false;
$dscan = array(realpath($dirname));
$darr = array();
while (!empty($dscan)) {
$dcur = array_pop($dscan);
$darr[] = $dcur;
if ($d=opendir($dcur)) {
while ($f=readdir($d)) {
if ($f=='.' || $f=='..')
continue;
$f=$dcur.'/'.$f;
if (is_dir($f))
$dscan[] = $f;
else
unlink($f);
}
closedir($d);
}
}
$i_until = ($only_empty)? 1 : 0;
for ($i=count($darr)-1; $i>=$i_until; $i--) {
rmdir($darr[$i]);
}
return (($only_empty)? (count(scandir)<=2) : (!is_dir($dirname)));
}
Sincerely,
Mike
--
Mike Brandonisio * Web Hosting
Tech One Illustration * Internet Marketing
tel (630) 759-9283 * e-Commerce
[EMAIL PROTECTED] * http://www.jikometrix.net
JIKOmetrix - Reliable web hosting
On Mar 5, 2007, at 6:54 AM, Muhammad Waqas wrote:
> Hello Experts,
> So far i m using following code for deleting folders and files.But
> it will
> only delete those folders which r empty.I want to delete those
> folders also
> which has some files.pls give me the solution
>
> <?php
> error_reporting(0);
> include("../connection.php");
> $date = date("m/d/Y"); //For finding current current
>
>
> function dateDiff($dformat, $endDate, $beginDate)
> {
> $date_parts1=explode($dformat, $beginDate);
> $date_parts2=explode($dformat, $endDate);
> $start_date=gregoriantojd($date_parts1[0], $date_parts1[1],
> $date_parts1[2]);
> $end_date=gregoriantojd($date_parts2[0], $date_parts2[1],
> $date_parts2[2]);
> return $end_date - $start_date;
> }
>
> ?>
>
> <?php
>
> $myqry = "select s.Mem_id, s.Order_date from stationary s, members
> M where
> M.id <http://m.id/> = s.Mem_id";
>
> $result = mysql_db_query($dbName,$myqry) or die("connect nahi hoa");
> $i = 0;
> while ($row = mysql_fetch_array($result))
> {
> $memidFORstationary[i] = $row[0];
> $dbdate[i] = date("m/d/Y", strtotime($row[1]));
> $difference[i] = dateDiff("/", $date, $dbdate[i]);
>
> if($difference[i] >13575)
> {
> $new_memidFORstationary[i] = $memidFORstationary[i];
> $memqry = "select UserId from members where Id =
> '$new_memidFORstationary[i]'";
> $mresult = mysql_db_query($dbName,$memqry);
> $urow = mysql_fetch_array($mresult);
> $foldername[i] = $urow[0];
> mysql_free_result($mresult);
> $dirpath[i] = "../client_uploads/".$foldername[i]."/stationary";
>
> $dh[i] = opendir($dirpath[i]);
> while ($temp[i] = readdir($dh[i]))
> {
>
> if ($temp[i]!='.' && $temp[i]!='..' && $temp[i]!='.htaccess')
>
> chmod($temp[i],777);
> }
>
>
> if(is_dir($dirpath[i]))
> {
> $dh[i] = opendir($dirpath[i]);
> while (false !== ($file[i] = readdir($dh[i])))
> {
> if (!is_dir("$dirpath[i]/$file[i]"))
> {
> unlink("../client_uploads/".$foldername[i]."/stationary/".$file[i]); }
> }
>
> rmdir("../client_uploads/".$foldername[i]."/stationary");
> rmdir("../client_uploads/".$foldername[i]);
> closedir($dh[i]);
> }
>
>
> }
>
> $i++;
> }
> mysql_close($db);
> unset($db);
> ?>
>
>
> Thanks,
> Waqas
> <http://www.youngcoders.com/editpost.php?do=editpost&p=115815>
>
>
> [Non-text portions of this message have been removed]
>
>
>
> ------------------------ Yahoo! Groups Sponsor --------------------
> ~-->
> Check out the new improvements in Yahoo! Groups email.
> http://us.click.yahoo.com/4It09A/fOaOAA/yQLSAA/HKFolB/TM
> --------------------------------------------------------------------
> ~->
>
> Community email addresses:
> Post message: [email protected]
> Subscribe: [EMAIL PROTECTED]
> Unsubscribe: [EMAIL PROTECTED]
> List owner: [EMAIL PROTECTED]
>
> Shortcut URL to this page:
> http://groups.yahoo.com/group/php-list
> Yahoo! Groups Links
>
>
>