Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.4.1

Request #2271 New flag for _rm_dir_recursive to leave directory structure intact
Submitted: 2004-09-02 13:40 UTC
From: joern_h at gmx dot net Assigned: jorrit
Status: Closed Package: Net_FTP
PHP Version: 4.3.0 OS: Win2000
Roadmaps: 1.4.0a2    
Subscription  
Comments Add Comment Add patch


Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem : 30 - 19 = ?

 
 [2004-09-02 13:40 UTC] joern_h at gmx dot net
Description: ------------ I needed a feature to recursively delete all files but keeping the directory structure intact. A Patch is attached. Reproduce code: --------------- --- FTP.php.jh Wed Sep 1 18:38:15 2004 +++ ftp.php Thu Sep 2 11:39:41 2004 @@ -1139,19 +1139,20 @@ * * @access public * @param string $path The absolute or relative path to the file / directory. * @param bool $recursive (optional) + * @param bool $files_only (optional) leave directory structure intact, delete only files * @return mixed True on success, otherwise PEAR::Error * @see NET_FTP_ERR_DELETEFILE_FAILED, NET_FTP_ERR_DELETEDIR_FAILED, NET_FTP_ERR_REMOTEPATHNODIR */ - function rm($path, $recursive = false) + function rm($path, $recursive = false, $files_only = false) { $path = $this->_construct_path($path); if ($this->_check_dir($path)) { if ($recursive) { - return $this->_rm_dir_recursive($path); + return $this->_rm_dir_recursive($path, $files_only); } else { return $this->_rm_dir($path); } } else { @@ -1868,9 +1869,9 @@ * @return mixed True on success, otherwise PEAR::Error * @see NET_FTP_ERR_REMOTEPATHNODIR, NET_FTP_ERR_DELETEDIR_FAILED */ - function _rm_dir_recursive($dir) + function _rm_dir_recursive($dir, $files_only = false) { if (substr($dir, (strlen($dir) - 1), 1) != "/") { return $this->raiseError("Directory name '$dir' is invalid, has to end with '/'", NET_FTP_ERR_REMOTEPATHNODIR); } @@ -1884,14 +1885,16 @@ } $dir_list = $this->_ls_dirs($dir); foreach ($dir_list as $new_dir) { $new_dir = $dir.$new_dir["name"]."/"; - $res = $this->_rm_dir_recursive($new_dir); + $res = $this->_rm_dir_recursive($new_dir, $files_only); if ($this->isError($res)) { return $res; } } - $res = $this->_rm_dir($dir); + if (!$files_only) { + $res = $this->_rm_dir($dir); + } if (!$res) { return $res; } else { return true;

Comments

 [2004-09-06 18:14 UTC] toby
Nice feature. Against which version is the patch?
 [2004-09-07 18:14 UTC] joern_h at gmx dot net
FTP.php says it is Net_FTP Version 1.3 $Id: FTP.php,v 1.26 2004/06/14 22:26:48 toby Exp $ I haven't worked with the pear bugtracker or with patches before so if you need more information or another patch format please tell me.
 [2004-09-22 17:29 UTC] toby
I will add that patch for the next minor release 1.4, since I don't wanna add new features in the current beta state.
 [2005-01-04 21:05 UTC] toby
I will add this feature into the coming version Net_FTP2.
 [2008-04-22 22:10 UTC] jorrit (Jorrit Schippers)
As Net_FTP2 will not be released soon, I've reopened this bug and added it as a feature to the 1.4 branch
 [2008-05-19 19:28 UTC] jorrit (Jorrit Schippers)
This bug has been fixed in CVS. If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET). If this was a problem with the pear.php.net website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better.