skip to Main Content

What is the PowerShell command for moving all files from folder A to folder B in an S3 bucket?

2

Answers


  1. You can use the AWS Command-Line Interface (CLI):

    aws s3 mv --recursive s3://my-bucket/folderA/ s3://my-bucket/folderB/
    

    It will perform a CopyObject and a DeleteObject object for each object in folderA.

    Login or Signup to reply.
  2. Move files from "folder" folderA to folderB in same bucket

    Get-S3Object -BucketName "mybucket" -Prefix "folderA/" | % { Copy-S3Object -BucketName "mybucket" -Key $_.Key -DestinationKey $($_.Key).Replace('folderA','folderB'); Remove-S3Object -BucketName "mybucket" -Key $_.Key -Force }
    

    To create an "empty folder" with only a / -named file, use this command. It will also be moved with the rest of the files if not excluded.

    Write-S3Object -BucketName mybucket -Key "folderA/" -Content "."
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search