Re: [PHP] Recurs Directory Delete

2006-07-14 Thread Adam Zey
So? Windows has this thing called the "del" command that does the same 
thing as "rm".


Regards, Adam.

Mark Steudel wrote:

I wish, I'm on an IIS box.

Mark

-Original Message-
From: Richard Lynch [mailto:[EMAIL PROTECTED] 
Sent: Friday, July 14, 2006 2:09 PM

To: tedd
Cc: Mark Steudel; php-general@lists.php.net
Subject: Re: [PHP] Recurs Directory Delete

On Fri, July 14, 2006 2:07 pm, tedd wrote:

At 11:55 AM -0700 7/14/06, Mark Steudel wrote:

I was hoping someone could give me a hand, I'm trying to create a
delete
folders function that recursively deletes folders and files from a
given
directory.


If you want to delete EVERYTHING, an exec("rm -r $path") could
potentially be much more efficient.

You'd be trading the cost of opening up a mini-shell against PHP
iteration, so it would depend on the number of directories, but if
there are LOTS of files, the rm -r will probably win.



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Recurs Directory Delete

2006-07-14 Thread Mark Steudel
Thanks all for the help, I figured it out:

This line was giving me grief :) doh!

while( false !== ( $file == readdir( $dir ) ) )

Mark


-Original Message-
From: Jochem Maas [mailto:[EMAIL PROTECTED] 
Sent: Friday, July 14, 2006 12:12 PM
To: Mark Steudel
Cc: php-general@lists.php.net
Subject: Re: [PHP] Recurs Directory Delete

Mark Steudel wrote:
> I was hoping someone could give me a hand, I'm trying to create a delete
> folders function that recursively deletes folders and files from a given
> directory. Here's what I have so far, but its not working I keep getting 
> 
> Warning: rmdir(wwwroot/resources/applications/44/series/25/modules/29)
> [function.rmdir]: Directory not empty in
> wwwroot\common\class.directories.php on line 28


do you have the relevant permissions to unlink() the files in question?
try dumping/collecting some debugging infomation a bit like this
function does:

/* delete everything in the $dir */
function recursiveDelete($dir)
{
$msgs = array(
"\n"."\n".'deleting everthing in: '.$dir,
 
"\n".'---'
);

if ($handle = /[EMAIL PROTECTED]/opendir($dir)) {
while (($file = readdir($handle)) !== false) {
if (($file == ".") || ($file == "..")) {
continue;
}

if (is_dir($dir.'/'.$file)) {
   // call self for this directory
   $msgs = array_merge($msgs, recursiveDelete($dir.'/'.$file));
   $r  = rmdir ($dir.'/'.$file);
   $msgs[] = "\n".'deleting dir.: '.$dir.'/'.$file.($r?'
SUCCESSFUL':' FAILED');
}
else {
   $r  = unlink($dir.'/'.$file); // remove this file
   $msgs[] = "\n".'deleting file: '.$dir.'/'.$file.($r?'
SUCCESSFUL':' FAILED');
}

}

/[EMAIL PROTECTED]/closedir($handle);
return $msgs;
}

/* return an array of messages always - for the call array_merge() */
return array();
}


> 
> function deleteFolders( $resource )
> {
>   if( is_dir( $resource ) )
>   {
>   if( $dir = opendir( $resource ) )
>   {
>   while( false !== ( $file == readdir( $dir ) ) )
>   {
>   if( $file != '.' && $file != '..' )
>   {
>   
> $this->deleteFolders($resource.'/'.$file );
>   }
>   }
>   closedir($dir);
>   rmdir($resource);
>   }
>   else 
>   {
>   $this->LOG .= __LINE__ . ": Unable to open
> directory\r\n";
>   }
>   }
>   else 
>   {
>   
>   if( is_file( $resource ) )
>   {   
>   unlink( $resource );
>   }
>   else 
>   {
>   $this->LOG .= __LINE__ . ": Unknown path:
> $resource\r\n";
>   }
>   }
> }
> 
> TIA, mark
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Recurs Directory Delete

2006-07-14 Thread Mark Steudel
I wish, I'm on an IIS box.

Mark

-Original Message-
From: Richard Lynch [mailto:[EMAIL PROTECTED] 
Sent: Friday, July 14, 2006 2:09 PM
To: tedd
Cc: Mark Steudel; php-general@lists.php.net
Subject: Re: [PHP] Recurs Directory Delete

On Fri, July 14, 2006 2:07 pm, tedd wrote:
> At 11:55 AM -0700 7/14/06, Mark Steudel wrote:
>>I was hoping someone could give me a hand, I'm trying to create a
>> delete
>>folders function that recursively deletes folders and files from a
>> given
>>directory.

If you want to delete EVERYTHING, an exec("rm -r $path") could
potentially be much more efficient.

You'd be trading the cost of opening up a mini-shell against PHP
iteration, so it would depend on the number of directories, but if
there are LOTS of files, the rm -r will probably win.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Recurs Directory Delete

2006-07-14 Thread Richard Lynch
On Fri, July 14, 2006 2:07 pm, tedd wrote:
> At 11:55 AM -0700 7/14/06, Mark Steudel wrote:
>>I was hoping someone could give me a hand, I'm trying to create a
>> delete
>>folders function that recursively deletes folders and files from a
>> given
>>directory.

If you want to delete EVERYTHING, an exec("rm -r $path") could
potentially be much more efficient.

You'd be trading the cost of opening up a mini-shell against PHP
iteration, so it would depend on the number of directories, but if
there are LOTS of files, the rm -r will probably win.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Recurs Directory Delete

2006-07-14 Thread Jochem Maas
Mark Steudel wrote:
> I was hoping someone could give me a hand, I'm trying to create a delete
> folders function that recursively deletes folders and files from a given
> directory. Here's what I have so far, but its not working I keep getting 
> 
> Warning: rmdir(wwwroot/resources/applications/44/series/25/modules/29)
> [function.rmdir]: Directory not empty in
> wwwroot\common\class.directories.php on line 28


do you have the relevant permissions to unlink() the files in question?
try dumping/collecting some debugging infomation a bit like this
function does:

/* delete everything in the $dir */
function recursiveDelete($dir)
{
$msgs = array(
"\n"."\n".'deleting everthing in: '.$dir,
"\n".'---'
);

if ($handle = /[EMAIL PROTECTED]/opendir($dir)) {
while (($file = readdir($handle)) !== false) {
if (($file == ".") || ($file == "..")) {
continue;
}

if (is_dir($dir.'/'.$file)) {
   // call self for this directory
   $msgs = array_merge($msgs, recursiveDelete($dir.'/'.$file));
   $r  = rmdir ($dir.'/'.$file);
   $msgs[] = "\n".'deleting dir.: '.$dir.'/'.$file.($r?' 
SUCCESSFUL':' FAILED');
}
else {
   $r  = unlink($dir.'/'.$file); // remove this file
   $msgs[] = "\n".'deleting file: '.$dir.'/'.$file.($r?' 
SUCCESSFUL':' FAILED');
}

}

/[EMAIL PROTECTED]/closedir($handle);
return $msgs;
}

/* return an array of messages always - for the call array_merge() */
return array();
}


> 
> function deleteFolders( $resource )
> {
>   if( is_dir( $resource ) )
>   {
>   if( $dir = opendir( $resource ) )
>   {
>   while( false !== ( $file == readdir( $dir ) ) )
>   {
>   if( $file != '.' && $file != '..' )
>   {
>   
> $this->deleteFolders($resource.'/'.$file );
>   }
>   }
>   closedir($dir);
>   rmdir($resource);
>   }
>   else 
>   {
>   $this->LOG .= __LINE__ . ": Unable to open
> directory\r\n";
>   }
>   }
>   else 
>   {
>   
>   if( is_file( $resource ) )
>   {   
>   unlink( $resource );
>   }
>   else 
>   {
>   $this->LOG .= __LINE__ . ": Unknown path:
> $resource\r\n";
>   }
>   }
> }
> 
> TIA, mark
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Recurs Directory Delete

2006-07-14 Thread tedd
At 11:55 AM -0700 7/14/06, Mark Steudel wrote:
>I was hoping someone could give me a hand, I'm trying to create a delete
>folders function that recursively deletes folders and files from a given
>directory.

This works for me:

 before delete");
echo ("");
print_r($file_array);   
echo("");

foreach ($file_array as $value)
{
unlink("$path/$value");
}
}
else
{
echo (" nothing to delete");
}
?>

hth's

tedd
-- 

http://sperling.com  http://ancientstones.com  http://earthstones.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php