note 50531 added to function.ftp-rmdir
| From: | hardcode1 at hotmail dot com | Date: | Wed, 02 Mar 2005 20:36:14 +0000 |
| Subject: | note 50531 added to function.ftp-rmdir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-85821@lists.php.net to get a copy of this message | ||
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.
----
Manual Page -- http://www.php.net/manual/en/function.ftp-rmdir.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+50531
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+50531&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+50531&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+50531&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+50531&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+50531&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+50531&report=yes
Search -- http://master.php.net/manage/user-notes.php