0
Script to create and name subfolder from selected files in Bridge
New Here
,
/t5/bridge-discussions/script-to-create-and-name-subfolder-from-selected-files-in-bridge/td-p/14718115
Jul 03, 2024
Jul 03, 2024
Copy link to clipboard
Copied
I have re-purposed some code I found on this forum for creating a subfolder automagically but there is one little tidbit I cannot figure out how to code correctly.
The goal is to grab a selection of RAW images, and create a folder with the name of the first image selected and move the images into it. I have functional code that does all of that, but I cannot figure out how to grab the name of the first file for the folder name. I have band-aided the code to ask for a name, but I am hoping that there is an easy solution for grabbing the first file name.
#target bridge
if(BridgeTalk.appName == 'bridge'){
selItems = MenuElement.create('command', 'Move DSC Images', 'at the end of Thumbnail');
}
selItems.onSelect = function(){
try{
var thumbs = app.document.selections;
var a = 0;
if(thumbs.length < 1) return;
var firstFile = prompt("Last 4 digits of first file name") ;
if (firstFile== undefined) {return};
var newFolder = new Folder(app.document.presentationPath+"/"+'DSC_'+firstFile+"/");
if(!newFolder.exists) newFolder.create();
var foldT = new Thumbnail (newFolder);
app.synchronousMode = true;
for(a = 0; a < thumbs.length; a++){
if(thumbs[a].parent != foldT){
var copyFile = File(newFolder.fsName + '/' + thumbs[a].name);
if(!copyFile.exists){
thumbs[a].moveTo(newFolder);
}
else{
var j = 1;
while(copyFile.exists){
var nSplit = thumbs[a].name.split('.');
ext = nSplit.pop();
thumbs[a].name = nSplit.join('.') + ' (' + j + ')' + '.' + ext;
copyFile = File(newFolder.fsName + '/' + thumbs[a].name);
j = j + 1;
}
thumbs[a].moveTo(newFolder);
}
}
}
app.synchronousMode = true;
app.document.chooseMenuItem('Refresh');
}
catch(e){
alert(e + e.line);
}
}
TOPICS
Batch
,
How to
,
Scripting
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Have something to add?
Join the conversation

