2

I have to move all files and folders from one folder to another of S3 bucket in php. I know a way to do the same thing is:

  1. Get all objects list from the source folder
  2. Copy all objects into destination folder
  3. Delete all objects from source folder

Then I know AWS don't have folders with some sort of hierarchy, it's only buckets based but now a days have any option or updates.

I am using Amazon S3 PHP Class version 0.4.0

  • Possible duplicate of [How to rename files and folder in Amazon S3?](https://stackoverflow.com/questions/21184720/how-to-rename-files-and-folder-in-amazon-s3) – salvatore Feb 02 '19 at 07:18

1 Answers1

4

Amazon S3 does not have a 'move' command. The only choice is to copy then delete.

The copy command tells S3 to copy the object, without requiring any downloads. Therefore, it is fast and efficient.

While S3 doesn't use folders, it does understand prefixes. The full path is part of the filename (Key). So, for example:

  • If you want to move folder1/foo.txt to folder2/foo.txt, then:
  • Copy folder1/foo.txt to folder2/foo.txt
  • Delete folder1/foo.txt

To use AWS with PHP, you should use the official AWS SDK for PHP.

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
  • Thanks for your comments . i know copy then delete but i need short cut i want to move files directly without using copy delete – saranya pandiyan Feb 02 '19 at 07:25
  • There is no shortcut. You could use the `aws s3 mv` command in the [AWS Command-Line Interface (CLI)](http://aws.amazon.com/cli/), but underneath it is still copying and deleting. What do you consider to be a "shortcut" -- do you want something that runs fast, or are you just looking for some copy/delete code that somebody else has written? – John Rotenstein Feb 02 '19 at 08:14