Any ways, here's my approach.
NOTE: There's no way to select multiple folders - only multiple file selections are allowed.
have subfolders be nested in Root Folder, and select this Root Folder via script. Like this:
... etc
Script will open Folder A and batch load images to single PSD file and save it as "Folder A.psd". Then will proceed to next folder Folder B and will work with those images and will save file as "Folder B.psd" etc. Hope this makes sense.
// Name: Batch Load Files into Layers.jsx
// Version: 1.0
// Release Date: 2016 10 13
//
// Developer: Tomas Sinkunas
// URL: www.rendertom.com
//
// Description:
// Select root folder that contains subfolders. if subfolders contain
// image files, then all images from current subfolder will be loaded
// to single Pthoshop File and saved to disk.
//
//
// This script is provided "as is," without warranty of any kind,
// expressed or implied. In no event shall author be held liable
// for any damages arising from the use of this script.
batchLoadFiles();
function batchLoadFiles() {
#target photoshop
var config = {
folders : [],
outputFolder : "",
}
buildUI();
function buildUI() {
var btnSize = 24;
var win = new Window('dialog', "Whatever, dude");
win.spacing = 10;
win.alignChildren = ["fill", "fill"];
win.group1 = win.add("group");
win.btnSelectFolders = win.group1.add("button", undefined, "Select Root Folder");
win.group2 = win.add("group");
win.stOutputFolder = win.group2.add('statictext', undefined, "Output Folder");
win.etOutputFolder = win.group2.add('edittext', undefined, config.outputFolder);
win.btnSelectOutputFolder = win.group2.add('button', undefined, "...");
win.group3 = win.add("group");
win.btnCloseWindow = win.group3.add('button',undefined, "Close", {name:'close'});
win.btnRunScript = win.group3.add('button',undefined, "Run Script", {name:'run Script'});
// Resize Buttons
win.stOutputFolder.preferredSize.width = 120;
win.etOutputFolder.preferredSize.width = 200;
win.btnSelectOutputFolder.preferredSize.width = btnSize * 2;
win.btnSelectFolders.alignment =
win.btnCloseWindow.alignment =
win.btnRunScript.alignment = ["fill", "fill"];
// button actions
win.btnSelectFolders.onClick = function () {
var rootFolder = Folder.selectDialog("Select root folder");
if (rootFolder === null) return;
var foldersArray = getFolders(rootFolder);
if (foldersArray.length === 0) {
alert("Selected folder does not contain any folders inside of it.");
return;
}
config.folders = foldersArray;
this.text = "Root Folder \"" + decodeURI(rootFolder.name) + "\" with " + foldersArray.length + " subfolders";
}
win.btnSelectOutputFolder.onClick = function() {
var outputFolder = Folder.selectDialog("Select output folder");
if (outputFolder) {
win.etOutputFolder.text = outputFolder.fsName;
config.outputFolder = outputFolder.fsName;
}
}
win.btnCloseWindow.onClick = function() {
win.close();
}
win.btnRunScript.onClick = function() {
if (config.folders.length === 0) {
alert("Select Root Folder first");
win.btnSelectFolders.active = true; return;
} else if (config.outputFolder === "" || !Folder(config.outputFolder).exists) {
alert("Output Folder does not exist\nPlease set Output Folder and try again");
win.etOutputFolder.active = true; return;
}
win.close();
main();
}
win.show();
}
function main() {
try {
for (var i = 0, il = config.folders.length; i < il; i ++) {
var folder = config.folders;
var files = folder.getFiles(/\.(jpg|tif|psd|bmp|gif|png|)$/i);
if (files.length > 0) {
for (var f = 0, fl = files.length; f < fl; f++) {
var file = files;
if (f === 0) {
var masterDoc = open(file);
masterDoc.layers[0].isBackgroundLayer = false;
masterDoc.layers[0].name = decodeURI ( masterDoc.name );
} else {
var doc = open(file);
var layer = doc.layers[0].duplicate(masterDoc);
app.activeDocument = masterDoc;
layer.name = decodeURI ( doc.name );
doc.close();
}
}
var outputPsdFile = config.outputFolder + "/" + folder.name + ".psd";
savePSD(outputPsdFile);
masterDoc.close();
}
}
} catch(e) {
alert(e.toString() + "\nLine: " + e.line.toString());
}
}
function savePSD(saveFile) {
psdSaveOptions = new PhotoshopSaveOptions();
psdSaveOptions.embedColorProfile = true;
psdSaveOptions.alphaChannels = true;
activeDocument.saveAs(File(saveFile), psdSaveOptions, false, Extension.LOWERCASE);
}
function getFolders(rootFolder) {
var folders = [];
var folderItems = rootFolder.getFiles();
for (var i = 0, il = folderItems.length; i < il; i ++) {
var curItem = folderItems;
if (curItem.constructor.name == "Folder") {
folders.push(curItem);
}
}
return folders;
}
}