cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

How to display the folder name in the output after folder creation?

Keerthivarman
13-Aquamarine

How to display the folder name in the output after folder creation?

Keerthivarman_0-1704890363636.png

i've created a service for creating folder in the repository, how can i get the created folder name in the output as string/text?

 

thanks

keerthi

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @Keerthivarman ,

 

I hope this below sample code may helps you in after uploading a file from File Upload - Widget it will create the a folder based on a selected file name and upload that file in that created folder.

 

var repositoryName = p_repositoryName;
var renamedFolderName = '';
if (p_fileName != null && p_fileName != undefined && p_fileName != "") {
	try {
		var SplitPath = p_fileName.split(".");
		renamedFolderName = SplitPath[0];
	} catch (e) {
		renamedFolderName = 'NewFile';
	}
	try {
		try {
			Things[repositoryName].CreateFolder({
				path: renamedFolderName /* STRING */
			});
			//logger.info("renamedFolderName - " + renamedFolderName);
		} catch (e) {}

		Things[repositoryName].MoveFile({
			targetPath: '/' + renamedFolderName + "/" + p_fileName /* STRING */ ,
			overwrite: false /* BOOLEAN */ ,
			sourcePath: "/" + p_fileName /* STRING */
		});
		//logger.info("Target - " + renamedFolderName + " ; Soruce Path - " + p_fileName);
		result = p_fileName + " - Successfully uploaded into the folder of " + renamedFolderName;
	} catch (e) {
		result = "Error in File Upload in New Folder - See Script Error Log for more details.";
	}
} else {
	result = "Please Enter Value In Folder Name";
}

 

Mashup Binding:

Arun_C_1-1704902635583.png

 

I'm not clear about the req split files into multiple. If you are looking to Extract the Zip/Archive means you can use the Repository Service of ExtractZipArchive/ExtractArchive in this case you don't need to create any seperate folder.

 

Thanks & Regards,

Arun C

 

View solution in original post

3 REPLIES 3

Hi @Keerthivarman ,

 

Based on my understanding you are trying to create new folders in repository using service once it done you need the STRING result in same service. In that case kindly find the smaple code attached, if not kindly explain more in your use case here.

 

var repositoryName = "DVC_Prod_ImageRepository";
if (p_folderName != null && p_folderName != undefined && p_folderName != "") {
	try {
		Things[repositoryName].CreateFolder({
			path: p_folderName /* STRING */
		});
		result = p_folderName + " - Folder Created Successfully!";
	} catch (e) {
		result = "Error in Folder Creation - See Script Error Log for more details.";
	}
} else {
	result = "Please Enter Value In Folder Name";
}

 

Expected Output:

Arun_C_1-1704894305889.png

 

Thanks & Regards,

Arun C

Keerthivarman
13-Aquamarine
(To:Arun_C)

Hi Arun,

 

Thanks for your answer!

 

Here i need is that, need to create a folder on selection of a file using file upload widget, with the selected filename and split the files into multiple and need to save it in the created folder itself

Hi @Keerthivarman ,

 

I hope this below sample code may helps you in after uploading a file from File Upload - Widget it will create the a folder based on a selected file name and upload that file in that created folder.

 

var repositoryName = p_repositoryName;
var renamedFolderName = '';
if (p_fileName != null && p_fileName != undefined && p_fileName != "") {
	try {
		var SplitPath = p_fileName.split(".");
		renamedFolderName = SplitPath[0];
	} catch (e) {
		renamedFolderName = 'NewFile';
	}
	try {
		try {
			Things[repositoryName].CreateFolder({
				path: renamedFolderName /* STRING */
			});
			//logger.info("renamedFolderName - " + renamedFolderName);
		} catch (e) {}

		Things[repositoryName].MoveFile({
			targetPath: '/' + renamedFolderName + "/" + p_fileName /* STRING */ ,
			overwrite: false /* BOOLEAN */ ,
			sourcePath: "/" + p_fileName /* STRING */
		});
		//logger.info("Target - " + renamedFolderName + " ; Soruce Path - " + p_fileName);
		result = p_fileName + " - Successfully uploaded into the folder of " + renamedFolderName;
	} catch (e) {
		result = "Error in File Upload in New Folder - See Script Error Log for more details.";
	}
} else {
	result = "Please Enter Value In Folder Name";
}

 

Mashup Binding:

Arun_C_1-1704902635583.png

 

I'm not clear about the req split files into multiple. If you are looking to Extract the Zip/Archive means you can use the Repository Service of ExtractZipArchive/ExtractArchive in this case you don't need to create any seperate folder.

 

Thanks & Regards,

Arun C

 

Top Tags