boxcli icon indicating copy to clipboard operation
boxcli copied to clipboard

Allow for the creation of folder structures with the folders:create command

Open pchristensenB opened this issue 2 years ago • 0 comments

Is your feature request related to a problem? Please describe.

Currently the folders:create endpoint can only create one folder per call which means creating deeper structures is complicated.

Describe the solution you'd like

With some additional logic the command for creating folders could check for '/' in the requested folder name and create the whole given path if a path is given rather than a folder

Describe alternatives you've considered

Alternatively this could be a separate command. eg. folders:createpath

Additional context

I did a proof of concept with the code below added to the folders:create command

if(params.body.name.includes('/')) {
			let pathParts = params.body.name.split('\/');
			let createdFolder;
			for (let i = 0; i < pathParts.length; i++) {
				params.body.name=pathParts[i];
				try {
					createdFolder = await this.client.folders.create(params.body.parent.id,params.body.name);
					params.body.parent.id=createdFolder.id
				}
				catch(error) {
					if(error.statusCode==409) {
						//console.log(error.response.body.context_info.conflicts[0].id);
						params.body.parent.id=error.response.body.context_info.conflicts[0].id;
						createdFolder=error.response.body.context_info.conflicts[0];
					}
				}
			};

Example command output image (1) image

IT would also work with files CSV like this

image (2)

pchristensenB avatar Nov 23 '21 16:11 pchristensenB