MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/nodejs-docs-samples / main

Function main

storage-control/renameFolder.js:18–61  ·  view source on GitHub ↗
(bucketName, sourceFolderName, destinationFolderName)

Source from the content-addressed store, hash-verified

16'use strict';
17
18function 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
63process.on('unhandledRejection', err => {
64 console.error(err.message);

Callers 1

renameFolder.jsFile · 0.70

Calls 1

callRenameFolderFunction · 0.85

Tested by

no test coverage detected