Rename a file if another with same name exists, adding hash of current date. It keep safe
the filename extension.

@param	string	Original file-name with or without extension.
@param	string	Path to file, with or without trailing slash.

@return	string
965814
public static function uniqueFilename($filename, $path) {
	
		// fixes path if not containing trailing slash
		self::fixTrailingSlash($path);
	
		if (file_exists($path . $filename)) {
			$dot  = strrpos($filename,'.');
			$ext  = substr($filename,$dot);
			$name = substr($filename,0,$dot);
			$hash = substr(md5(time()),0,6);
			$filename = $name . '-' . $hash . $ext;
		}
	
		return $filename;
	
	}
1267463
public function rename($pathname)
    {
        if (!empty($pathname)) {
            if ($this->exists()) {
                $targetPathname = $this->getPath() . self::PATH_SEPARATOR . (string)$pathname;
                if (rename($this->getPathname(), $targetPathname)) {
                    parent::__construct($targetPathname);
                    return true;
                }
            } else {
                throw new FileException('Rename failed, file or directory do not exist.');
            }
        } else {
            throw new FileException('Rename failed, because given filename is empty.');
        }
        return false;
    }
593317
public function moveFolder($originalPath, $newPath)
    {
        if (Str::lower($originalPath) !== Str::lower($newPath)) {
            // If there is no risk that the directory was renamed
            // by just changing the letter case in the name -
            // copy the directory to the destination path and delete
            // the source directory.

            if (!$this->copyFolder($originalPath, $newPath)) {
                return false;
            }

            $this->deleteFolder($originalPath);
        }
        else {
            // If there's a risk that the directory name was updated
            // by changing the letter case - swap source and destination
            // using a temporary directory with random name.

            $tempraryDirPath = $this->generateRandomTmpFolderName(dirname($originalPath));

            if (!$this->copyFolder($originalPath, $tempraryDirPath)) {
                $this->deleteFolder($tempraryDirPath);

                return false;
            }

            $this->deleteFolder($originalPath);

            return $this->moveFolder($tempraryDirPath, $newPath);
        }

        return true;
    }
1243913
public function generateUniqueFilename($originalFilename)
    {
        $index = 0;
        $filename = pathinfo($originalFilename, PATHINFO_FILENAME);
        $extension = pathinfo($originalFilename, PATHINFO_EXTENSION);

        while ($this->imageManager->findByFilename($originalFilename)) {
            $index++;
            $originalFilename = $filename . '-' . $index . '.' . $extension;
        }

        return $originalFilename;
    }
111611
public static function incrementFilename($path){
		$i = 1;
		$dir = dirname($path);
		$filename = basename($path);
		if(preg_match('#^(\d+)-(.*)$#',basename($path),$matches)){
			$i = (int) $matches[1];
			$filename = $matches[2];
		}
		do {
			$target = rtrim($dir,'/').'/'.self::cleanFilename($i++.'-'.$filename);
		} while(file_exists($target));
		return $target;
	}
84231
public function rename($path, $newpath)
    {
        $statusCopy = $this->copy($path, $newpath);
        $statusRemoveOld = $this->delete($path);

        return $statusCopy && $statusRemoveOld;
    }
1170637
protected function normalizeFilename($path)
	{
		if (file_exists($path)) {
			$path = realpath($path);
		}
		return substr($path,mb_strlen(realpath(dirname($_SERVER['DOCUMENT_ROOT']))));
	}
999981
public static function rename($path, $newpath, $cb = null, $pri = EIO_PRI_DEFAULT)
    {
        $cb = CallbackWrapper::forceWrap($cb);
        if (!self::$supported) {
            $r = rename($path, $newpath);
            if ($cb) {
                $cb($path, $newpath, $r);
            }
            return $r;
        }
        return eio_rename($path, $newpath, $pri, $cb, $path);
    }
165143
public static function move($path, $target, $fileName, $encryption = false, $newFilename = false)
    {
        $fileNameOld    = $fileName;
        $extension      = File::extension($fileName);
        $baseName       = basename($fileName, '.' . $extension);

        if ($encryption)
        {
            mt_srand();
            $fileName = md5(uniqid(mt_rand())) . "." . $extension;
        }
        elseif ($newFilename)
        {
            $fileName = $newFilename . "." . $extension;
        }

        $i = 0;
        while (File::exists($target . '/' . $fileName))
        {
            $i++;
            $fileName = $baseName . '-' . $i . '.' . $extension;
        }
        
        File::move($path . '/' . $fileNameOld, $target . '/' . $fileName);

        return $fileName;
    }
417185
public function rename($dir, $path, $new, $type = 'file'){
    if ( ($cfg = $this->dir($dir)) &&
      ($root = $this->get_root_path($dir)) &&
      bbn\str::check_filename($new)
    ){
      $is_file = $type === 'file';
      $wtype = $is_file ? 'file' : 'directory';
      $pi = pathinfo($path);
      $files = [];
      if ( $pi['filename'] !== $new ){
        if ( !empty($cfg['tabs']) ){
          $ext = false;
          foreach ( $cfg['tabs'] as $t ){
            if ( empty($t['fixed']) ){
              // MVC tab's path
              $real = $root . $t['path'];
              if ( $pi['dirname'] !== '.' ){
                $real .= $pi['dirname'] . '/';
              }
              if ( $is_file ){
                foreach ( $t['extensions'] as $e ){
                  $real_new = $real . $new . '.' . $e['ext'];
                  $real_ext = $real . $pi['filename'] . '.' . $e['ext'];
                  if ( file_exists($real_ext) ){
                    if ( !file_exists($real_new) ){
                      $ext = empty($ext) ? $e['ext'] : $ext;
                      $files[$real_ext] = $real_new;
                      if ( $t['url'] === 'php' ){
                        $change_perm = [
                          'old' => $real_ext,
                          'new' => $real_new,
                          'type' => 'file'
                        ];
                      }
                    }
                    else {
                      $this->error("The file $real_new is already exists.");
                      return false;
                    }
                  }
                }
                if ( !empty($t['default']) ){
                  $file_url = $this->real_to_url($real_ext);
                  $file_new_url = $this->real_to_url($real_new);
                }
              }
              else {
                $real_new = $real . $new;
                $real .= $pi['filename'];
                if ( file_exists($real) ){
                  if ( !file_exists($real_new) ){
                    $files[$real] = $real_new;
                    if ( $t['url'] === 'php' ){
                      $change_perm = [
                        'old' => $real,
                        'new' => $real_new,
                        'type' => 'dir'
                      ];
                    }
                  }
                  else {
                    $this->error("The directory $real_new is already exists.");
                    return false;
                  }
                }
              }
              if ( !empty($t['default']) ){
                $file_new = (($pi['dirname'] !== '.') ? $pi['dirname'] . '/' : '') . $new;
                $file_new_name = (($pi['dirname'] !== '.') ? $pi['dirname'] . '/' : '') . $new;
              }
            }
          }
        }
        else {
          $real = $root . $path;
          $real_new = $root . $new . ($is_file ?  '.' . $pi['extension'] : '');
          if ( file_exists($real) ){
            if ( !file_exists($real_new) ){
              $files[$real] = $real_new;
            }
            else {
              $this->error("The $wtype $real_new is already exists.");
              return false;
            }
            if ( $is_file ){
              $file_url = $this->real_to_url($real);
              $file_new_url = $this->real_to_url($real_new);
              $file_new = (($pi['dirname'] !== '.') ? $pi['dirname'] . '/' : '') . $new . '.' . $pi['extension'];
              $file_new_name = (($pi['dirname'] !== '.') ? $pi['dirname'] . '/' : '') . $new . '.' . $pi['extension'];
            }
            else {
              $file_new = (($pi['dirname'] !== '.') ? $pi['dirname'] . '/' : '') . $new;
              $file_new_name = (($pi['dirname'] !== '.') ? $pi['dirname'] . '/' : '') . $new;
            }
          }
        }

        foreach ( $files as $s => $d ){
          if ( !rename($s, $d) ){
            $this->error("Impossible to rename the $wtype: $s -> $d");
            return false;
          }
          if ( is_file($s) ){
            // Remove file's options
            $this->options->remove($this->options->from_code($this->real_to_id($s), $this->_files_pref()));
          }
          else {
            $this->rem_dir_opt($s);
          }
        }

        // Change permission
        if ( !empty($change_perm) ){
          $this->change_perm_by_real($change_perm['old'], $change_perm['new'], $change_perm['type']);
        }

        return [
          'file_url' => $file_url,
          'file_new_url' => $file_new_url,
          'file_new' => $file_new,
          'file_new_name' => $file_new_name,
          'file_new_ext' => $ext
        ];
      }
      $this->error("The old name and the new name are identical.");
      return false;
    }
  }
391779
public function rename($path, $newpath)
    {
        $pathinfo = pathinfo($path);
        if ($pathinfo['dirname'] != '.') {
            $path_remote = $pathinfo['dirname'] . '/' . $pathinfo['filename'];
        } else {
            $path_remote = $pathinfo['filename'];
        }

        $newpathinfo = pathinfo($newpath);
        if ($newpathinfo['dirname'] != '.') {
            $newpath_remote = $newpathinfo['dirname'] . '/' . $newpathinfo['filename'];
        } else {
            $newpath_remote = $newpathinfo['filename'];
        }

        $result = Uploader::rename($path_remote, $newpath_remote);

        return $result['public_id'] == $newpathinfo['filename'];
    }
49535
public static function getFileNameFromPath(string $path)
    {
        $split = explode('/', $path);
        $name = (string)end($split);

        return $name;
    }
510485
public function hashName($path = null)
    {
        if (! is_null($path)) {
            $path = rtrim($path, '/\\') .DS;
        }

        return $path .md5_file($this->path()) .'.' .$this->extension();
    }
508540
public function newFileFromName($path, $name, $hashName = false){
        $info = pathinfo($name);
        $ext = isset($info['extension'])? ".{$info['extension']}":"";
        $name = $info['filename'];
        $n = $hashName?md5($name):$name;
        $file = new FileImpl("$path/$n$ext");
        $i = 0;
        while($file->exists()){
            $i++;
            $n = $hashName?md5($name.$i):"$name ($i)";
            $file = new FileImpl("$path/$n$ext");
        }
        return $file;

    }
940427
public void rename(String oldpath, String newpath)
			throws SftpStatusException, SshException {
		String from = resolveRemotePath(oldpath);
		String to = resolveRemotePath(newpath);

		SftpFileAttributes attrs = null;

		try {
			attrs = sftp.getAttributes(to);

		} catch (SftpStatusException ex) {
			sftp.renameFile(from, to);
			return;
		}

		if (attrs != null && attrs.isDirectory()) {
			sftp.renameFile(from, to);
		} else {
			throw new SftpStatusException(
					SftpStatusException.SSH_FX_FILE_ALREADY_EXISTS, newpath
							+ " already exists on the remote filesystem");
		}

	}
1039318
public function rename($file = NULL, $extension = NULL)
	{
		$target = (!is_null($file) ? $this->filename : $this->extension);
		$replacement = (!is_null($file) ? $file .'.'. $this->extension : $extension);

		$this->file = str_replace($target, $replacement, $this->file);
	}
749821
public function hashName($path = null)
    {
        if ($path) {
            $path = rtrim($path, '/').'/';
        }

        $hash = $this->hashName ?: $this->hashName = Str::random(40);

        if ($extension = $this->guessExtension()) {
            $extension = '.'.$extension;
        }

        return $path.$hash.$extension;
    }