/** * Move file into another parent dir. * Return new file path or false. * * @param string $source source file path * @param string $target target dir path * @param string $name file name * @return string|bool **/ protected function _move($source, $target, $name) { $path = $this->_joinPath($target, $name); if ($this->fs->rename($source, $path)) { return $path; } return false; }
/** * Move (rename) a file or directory. * * @param string $source * @param string $destination * @throws IoWriteException */ public function move($source, $destination) { try { $this->fs->rename($source, $destination); } catch (Error $ex) { throw new IoWriteException("File {$source} could not be moved to {$destination}.", $ex); } catch (Exception $ex) { throw new IoWriteException("File {$source} could not be moved to {$destination}.", $ex); } }
/** * Migrates a file to the new strategy if it's not present * * @internal * @param $path * @return void */ public function migrateFile($path) { if ($this->getAdapterType() !== 'local' || $this->isEncoded($path)) { return; } $encodedPath = $this->strategy->encode($path); if ($this->filesystem->has($path) && !$this->filesystem->has($encodedPath)) { $this->filesystem->rename($path, $encodedPath); } }
/** @inheritdoc */ public function extract($zipBallPath, $to) { $absolutePathToZipBall = $this->filesystem->getAdapter()->applyPathPrefix($zipBallPath); if ($this->zip->open($absolutePathToZipBall) === true) { $absolutePathToExtract = $this->filesystem->getAdapter()->applyPathPrefix($to); $this->zip->extractTo($absolutePathToExtract); $this->zip->close(); $zipCreatedFolder = Linq::from($this->filesystem->listContents($to))->single(function ($object) { return $object['type'] == 'dir'; })['path']; foreach ($this->filesystem->listContents($zipCreatedFolder, true) as $object) { if ($object['type'] == "file") { $segments = explode('/', $object['path']); unset($segments[4]); $this->filesystem->rename($object['path'], implode('/', $segments)); } } $this->filesystem->deleteDir($zipCreatedFolder); return; } throw new ZipExtractionFailed($zipBall, $to); }
/** * @override * @inheritDoc */ public function move($source, $destination) { $ex = null; $status = false; try { $status = $this->fs->rename($source, $destination); } catch (Error $ex) { } catch (Exception $ex) { } if (!$status || $ex !== null) { throw new WriteException("File {$source} could not be moved to {$destination}.", $ex); } }
/** * Renames a file in this storage. * * @param string $fileIdentifier * @param string $newName The target path (including the file name!) * @return string The identifier of the file after renaming * @throws ExistingTargetFileNameException */ public function renameFile($fileIdentifier, $newName) { // Makes sure the Path given as parameter is valid $newName = $this->sanitizeFileName($newName); $newIdentifier = $this->canonicalizeAndCheckFileIdentifier($newName); // The target should not exist already if ($this->fileExists($newIdentifier)) { throw new ExistingTargetFileNameException('The target file "' . $newIdentifier . '" already exists.', 1320291063); } $sourcePath = ltrim($fileIdentifier, '/'); $targetPath = ltrim($newIdentifier, '/'); $result = $this->filesystem->rename($sourcePath, $targetPath); if ($result === false) { throw new \RuntimeException('Renaming file ' . $sourcePath . ' to ' . $targetPath . ' failed.', 1320375115); } return $newIdentifier; }
/** * Move a file to a new location. * * @param string $from * @param string $to * @return bool */ public function move($from, $to) { return $this->driver->rename($from, $to); }
/** * Move file into another parent dir. * Return new file path or false. * * @param string $source source file path * @param string $target target dir path * @param string $name file name * @return string|bool **/ protected function _move($source, $target, $name) { $path = $this->_joinPath($target, $name); return $this->_resultPath($this->fs->rename($source, $path), $path); }
/** * Rename a file. * * @param string $path Path to the existing file. * @param string $newpath The new path of the file. * * @throws FileExistsException Thrown if $newpath exists. * @throws FileNotFoundException Thrown if $path does not exist. * * @return bool True on success, false on failure. */ public function rename($path, $newpath) { return $this->fileSystem->rename($path, $newpath); }