Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X
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
Solved! Go to Solution.
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:
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
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:
Thanks & Regards,
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:
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