Home » Networking » Net_FTP » Bug #2271
New flag for _rm_dir_recursive to leave directory structure intact
Details
| 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 |
Comments
[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;
[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.