how to edit a script

Photoshop Script Snippets - Note: Full Scripts go in the Photoshop Scripts Forum

Moderators: Tom, Kukurykus

r4nd3r
Posts: 14
Joined: Fri Aug 05, 2016 12:29 pm

how to edit a script

Post by r4nd3r »

Hi

I need to add in a script only the " include all subfolders "

the script is the " Manual batch "


https://github.com/cgencer/ps-scripting ... al%20Batch

it would be possible?
User avatar
Dormeur74
Posts: 36
Joined: Mon Oct 03, 2016 4:56 am

Re: how to edit a script

Post by Dormeur74 »

Hi,

If you want to apply a script to the photos that are in subfolders, I think that the best way is to use a recursive function.
Here is an example I wrote to extract width and height of the photos found in a folder (and its subfolders, of course). Hope it will help.

Code: Select all


// Enables double clicking from the Macintosh Finder or the Windows Explorer
#target photoshop
app.bringToFront();

var inputFolder = Folder.selectDialog("Select the top folder where your images are : ");

if (inputFolder != null) {
filesArray = scanFolder(inputFolder);
if (filesArray.length > 0)
{
for (i = 0;i<filesArray.length;i++)
{
docRef = filesArray[i];
open(docRef);
imgWidth = app.activeDocument.width;
imgHeight = app.activeDocument.height;
alert(imgWidth+" x " +imgHeight);
}
}
}
alert("Done !");

// Recursive function
function scanFolder(folder) {
var filesArray = [],
fileList = folder.getFiles(),i, file;

for (i = 0; i < fileList.length; i++) {
file = fileList[i];
if (file instanceof Folder) {
filesArray = filesArray.concat(scanFolder(file));
}
else if (file instanceof File && file.name.match(/\.(jpg|tif|psd|bmp|gif|png|)$/i)) {
filesArray.push(file);
}
}
return filesArray;
}