IPWorks Cloud 2020 Node.js Edition

Questions / Feedback?

RenameFolder Method

Renames a folder.

Syntax

wasabi.renameFolder(folderName, newName, [callback])

Callback

The 'callback' parameter specifies a function which will be called when the operation completes (or an error is encountered). If the 'callback' parameter is not specified, then the method will block and will not return until the operation completes (or an error is encountered).

The callback for this method is defined as:

function(err){ }

'err' is the error that occurred. If there was no error, then 'err' is 'null'.

'err' has 2 properties which hold detailed information:

err.code
err.message

Remarks

This method renames the folder named FolderName to the name NewName. If NewName is already in use by existing folders, it will be overwritten if the current bucket has versioning enabled, or if the OverwriteOnRename configuration setting is set to true (default).

Since "folders" are in fact just name prefixes formatted to mimic a traditional file system, this method can rename multiple levels of "folders" at once by renaming a prefix. For example, assume you have the following objects in a bucket:

  • /pictures/animals/cats/cat1.jpg
  • /pictures/animals/cats/cat2.jpg
  • /pictures/animals/cats/cat3.jpg
  • /pictures/animals/cats/cat4.jpg
  • /pictures/animals/dogs/dog4.jpg
  • /pictures/animals/dogs/dog5.jpg

Doing the following command would leave you with the following objects in the bucket:
wasabi.RenameFolder("/pictures/animals/cats/", "pictures/pets/dogs");

  • /pictures/pets/dogs/cat1.jpg
  • /pictures/pets/dogs/cat2.jpg
  • /pictures/pets/dogs/cat3.jpg
  • /pictures/pets/dogs/cat4.jpg
  • /pictures/pets/dogs/dog4.jpg
  • /pictures/pets/dogs/dog5.jpg

And doing this command instead would leave you with these objects in the bucket, since the prefix being renamed now includes part of the "filename", and since (by default) the original "dog4.jpg" will get overwritten when "cat4.jpg" is renamed:
wasabi.RenameFolder("/pictures/animals/cats/cat", "pictures/pets/dogs/dog");

  • /pictures/pets/dogs/dog1.jpg
  • /pictures/pets/dogs/dog2.jpg
  • /pictures/pets/dogs/dog3.jpg
  • /pictures/pets/dogs/dog4.jpg
  • /pictures/pets/dogs/dog5.jpg

Copyright (c) 2022 /n software inc. - All rights reserved.
IPWorks Cloud 2020 Node.js Edition - Version 20.0 [Build 8265]