note 50531 deleted from function.ftp-rmdir by aidan
| From: | aidan@php.net | Date: | Fri, 29 Jul 2005 07:08:31 +0000 |
| Subject: | note 50531 deleted from function.ftp-rmdir by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-92691@lists.php.net to get a copy of this message | ||
Note Submitter: hardcode1 at hotmail dot com
----
Following the function listed below by "Sommerkorn at twt dot de" on a linux system
resulted in an infinite loop when I tested it, as the first entry in any folder listing is always
"." (current folder).
I have modified the function to skip the current and parent folders ("." and
".."):
<?php
function ftp_rmAll($conn_id,$dst_dir)
{
$ar_files = ftp_rawlist($conn_id, $dst_dir);
if (is_array($ar_files)) { // makes sure there are files
foreach ($ar_files as $st_file) { // for each file
if (ereg("([-d][rwxst-]+).* ([0-9]) ([a-zA-Z0-9]+).* ([a-zA-Z0-9]+).* ([0-9]*)
([a-zA-Z]+[0-9: ]*[0-9]) ([0-9]{2}:[0-9]{2}) (.+)",$st_file,$regs)) {
// ADDITION TO SKIP CURRENT AND PARRENT FOLDERS
if (($regs[8] == ".") || ($regs[8] == "..")) {
continue; }
if (substr($regs[1],0,1)=="d") { // check if it is a directory
ftp_rmAll($conn_id, $dst_dir."/".$regs[8]); // if so, use recursion
} else {
ftp_delete($conn_id, $dst_dir."/".$regs[8]); // if not, delete the file
}
}
}
}
ftp_rmdir($conn_id, $dst_dir); // delete empty directories
}
?>
Otherwise, good work everyone. I found this function very useful.