• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Folder and Sub-Folder Batch load Script

Contributor ,
Sep 21, 2011 Sep 21, 2011

Copy link to clipboard

Copied

What I'm looking for I'm not ever sure is possible, but what I need is a script that will search for predefined sub-folder names within a specific "root" folder and run a script I have to load those images into a Photoshop document found within the root folder.  When loading these images, it will also need to place the images into a specific group within the Photoshop document, depending on the sub-folder that contained them.  So images in the sub-folder "A" need to be loaded into the group "A" in the Photoshop document, images in sub-folder "B" into group "B" and so-on.  The number and name of images within the sub-folders are, however, random; so this would also need to be accounted for.  Additionally, if possible, I would like the script to ask the user to locate this root folder each time before proceeding; otherwise, if not possible, a static folder location can also be used.  Thanks for any help!

dgolberg

TOPICS
Actions and scripting

Views

2.1K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Oct 23, 2011 Oct 23, 2011

Does changing the line

if (checkPng(theObject) == true && theObject.name.match(theName)) {

to

if (checkPng(theObject) == true) {

help?

I looked over the thread and you seem to have made no mention of name-identity-condition, so I’m not sure why I included the name-check – probably a left-over from some other task.

Votes

Translate

Translate
Adobe
Community Expert ,
Sep 21, 2011 Sep 21, 2011

Copy link to clipboard

Copied

That is possible.

Images of which file-formats are to be processed?

Edit: Is the image to place those images in to be the active one?

Are the Groups to be created on running the Script or ar they already in the document?

Should the images be placed as Smart Objects and if not what is to be done about profile-mismatches?

Could you provide a list of the Folder-names?

Edit: Or better yet a screenshot of the Folder-structure and the corresponding resultant file’s Layer structure?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Sep 22, 2011 Sep 22, 2011

Copy link to clipboard

Copied

The image files will be .png format (with the exception of the base image which is .jpg).  The script would need to open the base image, add the groups, then import the images to the correct groups.

The folders/groups I'm using are:

trim

detail

extras

metals - sub groups/folders included in this folder

     stainless

     brushed

     rusted

     welded

paint

This is the maximum number of categories I'll get, though I'll usually not get all of them.  The images need to be copied as they are, not converted to smart objects.  The resolution on the source (.pngs) and target (the .jpg that opens first) files are the same, but can change project to project.  Thanks for taking a look at this; and if you need any more info, let me know.

dgolberg

edit: I wasn't quite sure what you meant on the profile mismatching.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 23, 2011 Sep 23, 2011

Copy link to clipboard

Copied

Profile-mismatches as in: When the container document and the image to be placed are of different Color Spaces (different ICC-profiles).

Could you give this a try (on a copy of your files naturally); it places as Smart Objects (depending on your Photoshop > Preferences > General settings), but you could always rasterize after the import or chenge the preference in the Scripts and reset it at the end:

// place png-files from a folder and its contained folders with groups to represent those in jpg-files;

// 2011, use it at your own risk;

#target photoshop

// select folder;

var theFolder = Folder.selectDialog ("select folder");

if (theFolder) {

// get the jpgs;

var theJpgs = getJpgFiles(theFolder);

// iterate through the jpg files;

for (var m = 0; m < theJpgs.length; m++) {

var theDoc = app.open(new File(theJpgs));

// thanks to xbytor;

var theName = theDoc.name.match(/(.*)\.[^\.]+$/)[1];

// place the png-files in groups coresponding to the folders;

placeFolderFiles(theFolder, theDoc, theName)

}

};

////////////////////////////////////

////////////////////////////////////

////////////////////////////////////

////// ceck for jpgs //////

function checkJpg (theFile) {

    if (theFile.name.match(/\.(jpg)$/i)) {

        return true

        };

          };

////// ceck for pngs //////

function checkPng (theFile) {

    if (theFile.name.match(/\.(png)$/i)) {

        return true

        };

          };

////// place //////

function placeScaleFile (file, xOffset, yOffset, theScale) {

// =======================================================

var idPlc = charIDToTypeID( "Plc " );

    var desc5 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

    desc5.putPath( idnull, new File( file ) );

    var idFTcs = charIDToTypeID( "FTcs" );

    var idQCSt = charIDToTypeID( "QCSt" );

    var idQcsa = charIDToTypeID( "Qcsa" );

    desc5.putEnumerated( idFTcs, idQCSt, idQcsa );

    var idOfst = charIDToTypeID( "Ofst" );

        var desc6 = new ActionDescriptor();

        var idHrzn = charIDToTypeID( "Hrzn" );

        var idPxl = charIDToTypeID( "#Pxl" );

        desc6.putUnitDouble( idHrzn, idPxl, xOffset );

        var idVrtc = charIDToTypeID( "Vrtc" );

        var idPxl = charIDToTypeID( "#Pxl" );

        desc6.putUnitDouble( idVrtc, idPxl, yOffset );

    var idOfst = charIDToTypeID( "Ofst" );

    desc5.putObject( idOfst, idOfst, desc6 );

    var idWdth = charIDToTypeID( "Wdth" );

    var idPrc = charIDToTypeID( "#Prc" );

    desc5.putUnitDouble( idWdth, idPrc, theScale );

    var idHght = charIDToTypeID( "Hght" );

    var idPrc = charIDToTypeID( "#Prc" );

    desc5.putUnitDouble( idHght, idPrc, theScale );

    var idLnkd = charIDToTypeID( "Lnkd" );

    desc5.putBoolean( idLnkd, true );

executeAction( idPlc, desc5, DialogModes.NO );

return app.activeDocument.activeLayer;

};

////// place images in folder and contained folders //////

function placeFolderFiles (theFolder, theContainer, theName) {

          var theContent = theFolder.getFiles();

          for (var n = theContent.length - 1; n >= 0; n--) {

                    var theObject = theContent;

                    if (theObject.constructor.name == "Folder") {

                              var aFolder = theContainer.layerSets.add();

                              aFolder.name = Folder(theContent).name;

                              placeFolderFiles(theObject, aFolder, theName)

                              };

                    if (checkPng(theObject) == true && theObject.name.match(theName)) {

                              var theLayer = placeScaleFile(theObject, 0, 0, 100);

                              theLayer.name = File(theObject).name;

                              theLayer.move(theContainer, ElementPlacement.PLACEATBEGINNING)

                              }

                    };

          };

////// place images in folder and contained folders //////

function getJpgFiles (theFolder) {

          if (!theArray) {var theArray = new Array};

          var theContent = theFolder.getFiles();

          for (var n = theContent.length - 1; n >= 0; n--) {

                    var theObject = theContent;

                    if (theObject.constructor.name == "Folder") {

                              theArray = theArray.concat(getJpgFiles(theObject))

                              };

                    if (checkJpg(theObject) == true) {

                              theArray.push(theObject)

                              }

                    };

          return theArray

          };

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Sep 24, 2011 Sep 24, 2011

Copy link to clipboard

Copied

Thanks! I'll try it out soon as I get some free time and let you know how it goes.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Sep 28, 2011 Sep 28, 2011

Copy link to clipboard

Copied

Sorry, been really busy with work these last few days, so I haven't had a chance to test it yet.  Once I do, I'll be sure to give you credit for a correct answer if it works. 

This is primarily for my personal use, but it would be handy for work as well.  Do you mind if I give the code to my employer once I get it working?  I'll be sure to add a code comment giving you credit for the help with it if it's alright with you, otherwise I'll keep it for personal use only.

dgolberg

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 28, 2011 Sep 28, 2011

Copy link to clipboard

Copied

Feel free to change and pass on the code as you see fit.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Oct 21, 2011 Oct 21, 2011

Copy link to clipboard

Copied

Finally got a chance to try out the script, but I've hit a bit of a snag.  It opens the .jpg in the main folder and creates all the groups based on the sub-folders correctly; but it doesn't grab the .png files and place them within the groups.  I tried messing around with it a bit, but couldn't seem to find the issue (parts of that code I'm not even sure how to read, I just know it's related to the script listener).  Anyway, any ideas why the .pngs aren't importing?

dgolberg

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 23, 2011 Oct 23, 2011

Copy link to clipboard

Copied

Does changing the line

if (checkPng(theObject) == true && theObject.name.match(theName)) {

to

if (checkPng(theObject) == true) {

help?

I looked over the thread and you seem to have made no mention of name-identity-condition, so I’m not sure why I included the name-check – probably a left-over from some other task.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Oct 23, 2011 Oct 23, 2011

Copy link to clipboard

Copied

That did the trick.  Thanks a bunch!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 09, 2022 Nov 09, 2022

Copy link to clipboard

Copied

Hi c.pfaffenbichler ! I am looking for a script like this, but it doesn't seem to work for me. I believe it has to do with the fact that most of my folders are empty.

I'm trying to import the complete folder structure as groups in photoshop, but I don't want to import the files contained in some of them, only the folder structure. 

Thanks in advance!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 17, 2022 Dec 17, 2022

Copy link to clipboard

Copied

LATEST

What exactly are you trying to automate? 

Have you found (or adapted) a Script in the meantime? 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines