12

As simple as it sounds, it seems like an extraordinarily complicated task.

John Topley
  • 113,588
  • 46
  • 195
  • 237
Trip
  • 26,756
  • 46
  • 158
  • 277

5 Answers5

12

Seems like the AWS Command Line Interface is the new way to do stuff like this. Using it, you can rename a folder like this:

aws s3 mv --recursive s3://bucketname/oldfoldername s3://bucketname/newfoldername

Be sure and start with the --dryrun option to make sure it will do what you think it's going to do.

Dan Tenenbaum
  • 1,809
  • 3
  • 23
  • 35
12

If you're using the aws-s3 gem, the following code will rename folder OLD_FOLDER_NAME in bucket BUCKET_NAME to NEW_FOLDER_NAME:

bsize = OLD_FOLDER_NAME.size
bucket = AWS::S3::Bucket.find(BUCKET_NAME)
bucket.objects({:prefix=>OLD_FOLDER_NAME}).each do |o|
  AWS::S3::S3Object.rename(o.key, NEW_FOLDER_NAME + o.key[bsize..-1], BUCKET_NAME)
end

That's it. Folders aren't real objects, so all you have to do is rename all the objects that end up in that specific path to the new path. The virtual folder will be renamed as a result.

Bradley Priest
  • 7,438
  • 1
  • 29
  • 33
Ronen Botzer
  • 6,951
  • 22
  • 41
  • This renames the folder, however, if the contents of the folder were public, those permissions seem to be lost during the rename. – jpw Dec 15 '13 at 21:44
  • added explicit permission as 4th parameter to the rename() sets the permissions :access => :public_read though there is probably some way to preserve permissions during the rename – jpw Dec 15 '13 at 21:53
2

If you use the S3 Management Console, you can cut and paste. Go into the folder you want, click Ctrl + A, then click Actions > Cut. Make your new folder and click Actions > Paste.

Brendan
  • 868
  • 1
  • 16
  • 38
0

Use BucketExplorer! This is a great app! You can do pretty much anything you ever wanted to do to your s3 in a very very easy to understand GUI

Trip
  • 26,756
  • 46
  • 158
  • 277
  • No honestly, I'm still open for ideas, but this was the best option I found. – Trip May 18 '12 at 18:30
  • I would agree were it not for the fact this solution requires Java7 to be installed, which can introduce quite a lot of system-level change simply to rename a folder. Too bad they don't re-write it as a 'real' app without the massive headache of java dependencies. – jpw Dec 15 '13 at 21:56
0

Go into the S3 console and use the following:

aws s3 --recursive mv s3://<bucketname>/<folder_name_from> s3://<bucket>/<folder_name_to>
Koedlt
  • 4,286
  • 8
  • 15
  • 33
m360ai
  • 1