Exemplo n.º 1
0
 /**
  * Moves a file or directory to a new location
  * 
  * <code>
  * \bbn\file\dir::move("C:\Documents\Test\Old", "C:\Documents\Test\New");
  * </code>
  * 
  * @param string $orig The file to be moved
  * @param string $dest The full name of the destination (including basename)
  * @param mixed $st If $st === true it will be copied over if the destination already exists, otherwise $st will be used to rename the new file in case of conflict
  * @param int $length The number of characters to use for the revision number; will be zerofilled
  * 
  * @return string the (new or not) name of the destination or false
  */
 public static function move($orig, $dest, $st = '_v', $length = 0)
 {
     if (file_exists($orig) && self::create_path(dirname($dest))) {
         if (file_exists($dest)) {
             if ($st === true) {
                 self::delete($dest);
             } else {
                 $i = 1;
                 while ($i) {
                     $dir = dirname($dest) . '/';
                     $file_name = \bbn\str\text::file_ext($dest, 1);
                     $file = $file_name[0] . $st;
                     if ($length > 0) {
                         $len = strlen(\bbn\str\text::cast($i));
                         if ($len > $length) {
                             return false;
                         }
                         $file .= str_repeat('0', $length - $len);
                     }
                     $file .= \bbn\str\text::cast($i);
                     if (!empty($file_name[1])) {
                         $file .= '.' . $file_name[1];
                     }
                     $i++;
                     if (!file_exists($dir . $file)) {
                         $dest = $dir . $file;
                         $i = false;
                     }
                 }
             }
         }
         if (rename($orig, $dest)) {
             return basename($dest);
         }
     }
     return false;
 }
Exemplo n.º 2
0
 /**
  * @return void 
  */
 public function listFiles($path = '.')
 {
     $res = [];
     if ($this->cn && @ftp_chdir($this->cn, $path) && ($files = ftp_nlist($this->cn, $path))) {
         foreach ($files as $file) {
             $ele = ['name' => $file, 'basename' => basename($file)];
             if (@ftp_chdir($this->cn, $path . '/' . $ele['basename'])) {
                 $num = ftp_nlist($this->cn, '.');
                 $ele['num'] = count($num);
                 $ele['type'] = 'dir';
                 @ftp_cdup($this->cn);
             } else {
                 $ele['type'] = \bbn\str\text::file_ext($file);
             }
             array_push($res, $ele);
         }
         return $res;
     }
     return false;
 }
Exemplo n.º 3
0
 function tree($path, $ver_path, $c = false, $ext = false)
 {
     $res = [];
     foreach (\bbn\file\dir::get_files($path, 1) as $p) {
         if (empty($ext) || !empty($ext) && (\bbn\str\text::file_ext($p) === $ext || \bbn\str\text::file_ext($p) === '')) {
             $pa = substr($p, strlen($ver_path), strlen($p));
             $r = ['text' => basename($p), 'path' => strpos($pa, '/') === 0 ? substr($pa, 1, strlen($pa)) : $pa];
             if (!empty($c) && in_array($r['path'], $c)) {
                 $r['checked'] = 1;
             }
             if (is_dir($p)) {
                 $r['items'] = tree($p, $ver_path, $c, $ext);
             }
             if (!is_dir($p) || is_dir($p) && !empty($r['items'])) {
                 array_push($res, $r);
             }
         }
     }
     return $res;
 }