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

List subfolders in a function

Community Beginner ,
Aug 08, 2017 Aug 08, 2017

Copy link to clipboard

Copied

Hi,

I want to add a small function to a script that logs the name of every subfolder in the root folder/parent folder of the one I am working from.

Here is what I have so far:

var docRef = app.activeDocument;

var sourceFolder = Folder (docRef.path);

var sourceName = sourceFolder.name;

var rootFolder= Folder (sourceFolder.path);

var rootName = rootFolder.name;

function sLog (){

    var folderName = String(rootFolder.name);

    var sub = folderName.includeSubFolders;

    alert (sub);

    }

sLog();

I want the alert to be able to list every folder.

Any ideas?

TOPICS
Actions and scripting

Views

1.6K

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

Guide , Aug 08, 2017 Aug 08, 2017

#target photoshop;

var folders =[];

var topLevel = Folder.selectDialog("Please select top level folder");   

folders = FindAllFolders(topLevel, folders);

folders.unshift(topLevel);

var List = [];

for(var a in folders){List.push(decodeURI(folders.name));}

alert(List.join("\n"));

function FindAllFolders( srcFolderStr, destArray) {

    var fileFolderArray = Folder( srcFolderStr ).getFiles();

    for ( var i = 0; i < fileFolderArray.length; i++ ) {

        var fileFoldObj = fileFolderArray;

        if ( fileFo

...

Votes

Translate

Translate
Adobe
Guide ,
Aug 08, 2017 Aug 08, 2017

Copy link to clipboard

Copied

Something like this.

#target photoshop;

var folders =[];

var topLevel = Folder.selectDialog("Please select top level folder");   

folders = FindAllFolders(topLevel, folders);

folders.unshift(topLevel);

alert(folders.join("\n"));

function FindAllFolders( srcFolderStr, destArray) {

    var fileFolderArray = Folder( srcFolderStr ).getFiles();

    for ( var i = 0; i < fileFolderArray.length; i++ ) {

        var fileFoldObj = fileFolderArray;

        if ( fileFoldObj instanceof File ) {           

        } else {

         destArray.push( Folder(fileFoldObj) );

        FindAllFolders( fileFoldObj.toString(), destArray );

        }

    }

    return destArray;

};

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 Beginner ,
Aug 08, 2017 Aug 08, 2017

Copy link to clipboard

Copied

Cheers Merlin, this result includes the full path.

Any ideas on how to remove the path "~/Documents/Base/FileName" so it just shows "FileName" for the list?

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
Guide ,
Aug 08, 2017 Aug 08, 2017

Copy link to clipboard

Copied

#target photoshop;

var folders =[];

var topLevel = Folder.selectDialog("Please select top level folder");   

folders = FindAllFolders(topLevel, folders);

folders.unshift(topLevel);

var List = [];

for(var a in folders){List.push(decodeURI(folders.name));}

alert(List.join("\n"));

function FindAllFolders( srcFolderStr, destArray) {

    var fileFolderArray = Folder( srcFolderStr ).getFiles();

    for ( var i = 0; i < fileFolderArray.length; i++ ) {

        var fileFoldObj = fileFolderArray;

        if ( fileFoldObj instanceof File ) {           

        } else {

         destArray.push( Folder(fileFoldObj) );

        FindAllFolders( fileFoldObj.toString(), destArray );

        }

    }

    return destArray;

};

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 Beginner ,
Aug 08, 2017 Aug 08, 2017

Copy link to clipboard

Copied

Super!

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 ,
Jun 22, 2023 Jun 22, 2023

Copy link to clipboard

Copied

for me there was an error in this code that i corrected by adding an index [i] to the following line:

        var fileFoldObj = fileFolderArray;

 

 

changing it to:

        var fileFoldObj = fileFolderArray[i];

 solved it for me!

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 ,
Jun 22, 2023 Jun 22, 2023

Copy link to clipboard

Copied

LATEST

@tales23460045id4y – Yes, the change in forum software broke the old code formatting. Good job in fixing it!

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