From c3da36c800ddac04b4e3bf7b80b98962b4bf6a9b Mon Sep 17 00:00:00 2001 From: Michael Larabel Date: Mon, 29 Dec 2008 12:11:49 -0500 Subject: pts-core: Rewrite pts_remove() function --- pts-core/functions/pts-functions_shell.php | 39 ++++++++++++++---------------- 1 file changed, 18 insertions(+), 21 deletions(-) (limited to 'pts-core') diff --git a/pts-core/functions/pts-functions_shell.php b/pts-core/functions/pts-functions_shell.php index ae54a28..7c4c715 100644 --- a/pts-core/functions/pts-functions_shell.php +++ b/pts-core/functions/pts-functions_shell.php @@ -77,37 +77,34 @@ function pts_download($download, $to) } function pts_remove($object, $ignore_files = null) { - if(!file_exists($object)) + if(is_dir($object) && substr($object, -1) != "/") { - return false; + $object .= "/"; } - if(is_file($object)) + foreach(glob($object . "*") as $to_remove) { - if(is_array($ignore_files) && in_array(basename($object), $ignore_files)) + if(is_file($to_remove)) { - return true; + if(is_array($ignore_files) && in_array(basename($to_remove), $ignore_files)) + { + continue; // Don't remove the file + } + else + { + @unlink($to_remove); + } } - else + else if(is_dir($to_remove)) { - return @unlink($object); - } - } + pts_remove($to_remove, $ignore_files); - if(is_dir($object)) - { - $directory = @dir($object); - while(($entry = $directory->read()) !== false) - { - if($entry != "." && $entry != "..") - { - pts_remove($object . "/" . $entry, $ignore_files); - } + //if(count(glob($to_remove . "/*")) == 0) + //{ + @rmdir($object); + //} } - $directory->close(); } - - return @rmdir($object); } function pts_copy($from, $to) { -- cgit