(bucketName, sourceFolderName, destinationFolderName)
| 16 | 'use strict'; |
| 17 | |
| 18 | function main(bucketName, sourceFolderName, destinationFolderName) { |
| 19 | // [START storage_control_rename_folder] |
| 20 | /** |
| 21 | * TODO(developer): Uncomment these variables before running the sample. |
| 22 | */ |
| 23 | |
| 24 | // The name of your GCS bucket |
| 25 | // const bucketName = 'bucketName'; |
| 26 | |
| 27 | // The source folder name |
| 28 | // const sourceFolderName = 'currentFolderName'; |
| 29 | |
| 30 | // The destination folder ID |
| 31 | // const destinationFolderName = 'destinationFolderName'; |
| 32 | |
| 33 | // Imports the Control library |
| 34 | const {StorageControlClient} = require('@google-cloud/storage-control').v2; |
| 35 | |
| 36 | // Instantiates a client |
| 37 | const controlClient = new StorageControlClient(); |
| 38 | |
| 39 | async function callRenameFolder() { |
| 40 | const folderPath = controlClient.folderPath( |
| 41 | '_', |
| 42 | bucketName, |
| 43 | sourceFolderName |
| 44 | ); |
| 45 | |
| 46 | // Create the request |
| 47 | const request = { |
| 48 | name: folderPath, |
| 49 | destinationFolderId: destinationFolderName, |
| 50 | }; |
| 51 | |
| 52 | // Run request |
| 53 | await controlClient.renameFolder(request); |
| 54 | console.log( |
| 55 | `Renamed folder ${sourceFolderName} to ${destinationFolderName}.` |
| 56 | ); |
| 57 | } |
| 58 | |
| 59 | callRenameFolder(); |
| 60 | // [END storage_control_rename_folder] |
| 61 | } |
| 62 | |
| 63 | process.on('unhandledRejection', err => { |
| 64 | console.error(err.message); |
no test coverage detected