rename() public static méthode

Renames a file or directory.
public static rename ( $name, $newName, $overwrite = TRUE ) : void
Résultat void
 /**
  * @param string $oldIdGallery
  * @param string $newIdGallery
  * @param string $oldLang
  * @param string $newLang
  */
 public function renameGallery($oldIdGallery, $newIdGallery, $oldLang, $newLang)
 {
     b($oldIdGallery, 'oI');
     b($newIdGallery, 'nI');
     b($oldLang, 'oL');
     b($newLang, 'nL');
     FileSystem::rename(galleryPath . $oldIdGallery . '_' . $oldLang, galleryPath . $newIdGallery . '_' . $newLang);
 }
 /**
  * Funkce pro extrakci konkrétního souboru ze ZIP archívu (na místo původního souboru)
  * @param string $fileName
  * @param int $selectedFileIndex
  * @throws \Exception
  */
 public function uncompressFileFromZipArchive($fileName, $selectedFileIndex)
 {
     $fileName = $this->getFilePath($fileName);
     try {
         FileSystem::delete($fileName . '.unzipped');
     } catch (\Exception $e) {
         /*ignore error*/
     }
     if (ZipImport::unzipFile($fileName, $selectedFileIndex, $fileName . '.unzipped')) {
         FileSystem::rename($fileName . '.unzipped', $fileName, true);
     } else {
         throw new \Exception('Unzip failed.');
     }
 }
Exemple #3
0
 /**
  * @param Nette\Application\UI\Form $form
  * @param                           $values
  * @throws InvalidPathException
  */
 public function renameFormSubmitted(Nette\Application\UI\Form $form, $values)
 {
     if ($form->submitted === $form['rename']) {
         $newName = $values->name . ($this->fileManager->isFeatureEnabled('renameExtension') ? '' : '.' . (new \SplFileInfo($values->file))->getExtension());
         if ($this->fileManager->isFeatureEnabled('renameFile') && $values->file != $newName) {
             $old = self::getPath($this, $values->file);
             $new = self::getPath($this, $newName);
             if (!Zax\Utils\PathHelpers::isSubdirOf($this->getRoot(), $new, TRUE)) {
                 throw new InvalidPathException('Invalid name specified.');
             }
             Nette\Utils\FileSystem::rename($old, $new);
             $this->onFileRename($old, $new);
             $this->flashMessage('fileManager.alert.fileRenamed', 'success');
         }
     }
     $this->fileList->go('this', ['view' => 'Default']);
 }
Exemple #4
0
 /**
  * @param Nette\Application\UI\Form $form
  * @param                           $values
  * @throws InvalidPathException
  */
 public function renameFormSubmitted(Nette\Application\UI\Form $form, $values)
 {
     $newName = $values->dir;
     if ($this->fileManager->isFeatureEnabled('renameDir') && $form->submitted === $form['rename']) {
         $newName = $values->name;
         if ($values->dir != $newName) {
             $dir = $this->getAbsoluteDirectory();
             $newPath = Zax\Utils\PathHelpers::rename($dir, $newName);
             if (!Zax\Utils\PathHelpers::isSubdirOf($this->getRoot(), $newPath, TRUE)) {
                 throw new InvalidPathException('Invalid name specified - ' . $newPath . ' is not inside ' . $this->getRoot());
             }
             Nette\Utils\FileSystem::rename($dir, $newPath);
             $this->onDirRename($dir, $newPath);
             $this->flashMessage('fileManager.alert.dirRenamed', 'success');
             $newPath = str_replace($this->root, '', $newPath);
             $this->fileManager->setDirectory($newPath);
             $this->fileManager->go('this', ['view' => 'Default', 'dir' => $newPath, 'directoryList-view' => 'Default']);
         }
     }
 }
Exemple #5
0
 /**
  * Moves image to target
  *
  * @param \Imager\ImageInfo $image
  * @param string $target
  * @return \Imager\ImageInfo
  */
 private function moveImage(ImageInfo $image, $target)
 {
     FileSystem::rename($image->getPathname(), $target);
     chmod($target, 0666);
     return new ImageInfo($target);
 }
 /**
  * @param string
  */
 private function moveData($dataPath)
 {
     if ($this->verbose) {
         $this->writeln('Moving pages data');
     }
     try {
         FileSystem::delete($this->dataPath);
     } catch (\Nette\IOException $e) {
         throw new \NetteAddons\InvalidStateException('Moving pages data failed', NULL, $e);
     }
     $dataPath = $this->getBaseDataPath($dataPath);
     foreach (Finder::findFiles('*')->from($dataPath) as $file) {
         /** @var \SplFileInfo $file */
         $destinationPath = str_replace($dataPath, $this->dataPath, $file->getRealPath());
         FileSystem::rename($file->getRealPath(), $destinationPath);
     }
 }
Exemple #7
0
<?php

/**
 * Created by PhpStorm.
 * User: Azathoth
 * Date: 11. 1. 2016
 * Time: 15:30
 */
require_once 'vendor/autoload.php';
use Nette\Utils\Finder;
use Nette\Utils\Strings;
/** @var \SplFileInfo $file */
foreach (Finder::findFiles('dolù*')->from(__DIR__ . '/imagesNew') as $file) {
    echo $file->getBasename() . PHP_EOL;
    \Nette\Utils\FileSystem::rename($file->getPathname(), Strings::replace($file->getPathname(), '~ù~', 'u'));
}
$translateColors = ['FIALOVÝ' => 'violet', 'ZELENEJ' => 'green', 'MODREJ' => 'blue', 'ÈERVENÝ' => 'red', 'ÈERNEJ' => 'black'];
foreach ($translateColors as $czech => $english) {
    /** @var \SplFileInfo $file */
    foreach (Finder::findDirectories("{$czech}*")->from(__DIR__ . '/imagesNew') as $file) {
        echo $file->getBasename() . PHP_EOL;
        \Nette\Utils\FileSystem::rename($file->getPathname(), Strings::replace($file->getPathname(), "~{$czech}~", $english));
    }
}
Exemple #8
0
 public function saveThumb($thumbPath, $identifier, $type)
 {
     $targetThumbPath = $this->root . $this->getThumbPath($identifier, $type);
     FileSystem::rename($thumbPath, $targetThumbPath, true);
 }
 /**
  * Renames a file or directory.
  *
  * @param string $name      Name
  * @param string $newName   New name
  * @param bool   $overwrite Allow overwrite
  *
  * @return void
  */
 public function rename($name, $newName, $overwrite = true)
 {
     \Nette\Utils\FileSystem::rename($name, $newName, $overwrite);
 }