title: How to copy/move all objects in Amazon S3 from one prefix to other using the AWS SDK for Node.js
body: <p>How do I copy all objects from one prefix to other? I have tried all possible ways to copy all objects in one shot from one prefix to other, but the only way that seems to work is by looping over a list of objects and copying them one by one. This is really inefficient. If I have hundreds of files in a folder, will I have to make 100 calls?</p>
  
  <pre><code>var params = {
           Bucket: bucket,
           CopySource: bucket+'/'+oldDirName+'/filename.txt',
           Key: newDirName+'/filename.txt',
   };
  s3.copyObject(params, function(err, data) {
    if (err) {
        callback.apply(this, [{
            type: "error",
            message: "Error while renaming Directory",
            data: err
        }]);
    } else {
        callback.apply(this, [{
            type: "success",
            message: "Directory renamed successfully",
            data: data
        }]);
    }
  });
  </code></pre>