rename a directory or a file

24,993

Solution 1

Laravel Docs

The move method may be used to rename or move an existing file to a new location:

Storage::move('hodor/file1.jpg', 'holdthedoor/file2.jpg');

this way, you can rename without moving

Storage::move('hodor/oldfile-name.jpg', 'hodor/newfile-name.jpg'); // keep the same folder to just rename 

Source

Solution 2

You can rename directories using

Storage::rename('oldFolder/', 'newFolder/');
Share:
24,993

Related videos on Youtube

Juliver Galleto
Author by

Juliver Galleto

Will I am just a just a just a just simple man who loves to code around. :D

Updated on October 09, 2022

Comments

  • Juliver Galleto
    Juliver Galleto over 1 year

    I'm using Laravel 5.0 Facades Storage

    use Illuminate\Support\Facades\Storage;

    and I can use it like

    Storage::..
    

    In the Laravel 5.0 Docs,there's nothing like rename a file or folder from the storage.

    Any help, ideas, clues, suggestions, recommendations on how to rename a file or folder using the Storage?

  • Juliver Galleto
    Juliver Galleto almost 8 years
    i see, in php it could be like 'rename(oldname,newname,context)' so I'm looking for Laravel's way, anyway, thanks for the answer, how can I rename the file without moving it?
  • Achraf Khouadja
    Achraf Khouadja almost 8 years
    i will edit answer,, actualy its easy check edit (i just tested the answer and it works 100% )
  • eskimo
    eskimo over 3 years
    Was looking for an answer to this question. Both using rename and move for renaming a folder doesn't work. Any ideas?

Related