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

Use getFiles() in an array

New Here ,
Nov 11, 2016 Nov 11, 2016

Copy link to clipboard

Copied

Hi all,

I'm trying to write a script which searches a folder for packaged files and then searches the links of those files.

I want to store the links and their files separate arrays.

When I put the packaged files in an array I cant seem to use the getFiles() function.

var links = [],
packaged = [],
files = [],
myFolder = Folder( "A:\jake/" ),
myDocs = [],
myFiles = myFolder.getFiles(),  //store the target files in a variable
i;

for ( i = 0; i < myFiles.length; i++ ) {
   
     if (myFiles instanceof Folder ) {
        
    var links = myFiles.getFiles( "Links" )
    packaged.push( links );
      
    }
   
    }

this is a snippet. The packaged array contains all the links folders but when I try and loop through them

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

   

    var y = packaged.getFiles()

    links.push( y );

   

    }

This doesn't work.

Any ideas?

TOPICS
Scripting

Views

951

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

Mentor , Nov 11, 2016 Nov 11, 2016

Hi,

"Links" is not an extension (to filter) but a name of folder (a part of path), so:

var links = Folder(myFiles + "/Links/").getFiles();

jarek

Votes

Translate

Translate
Mentor ,
Nov 11, 2016 Nov 11, 2016

Copy link to clipboard

Copied

Hi,

"Links" is not an extension (to filter) but a name of folder (a part of path), so:

var links = Folder(myFiles + "/Links/").getFiles();

jarek

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 11, 2016 Nov 11, 2016

Copy link to clipboard

Copied

Thanks

I'm using this:

var links = [],
packaged = [],
files = [],
myFolder = Folder( "A:\jake/" ),
myDocs = [],
myFiles = myFolder.getFiles(),  //store the target files in a variable
i;

for ( i = 0; i < myFiles.length; i++ ) {
   
     if ( myFiles instanceof Folder ) {
        
    packaged.push( Folder(myFiles + "/Links/").getFiles() );
    }
   
    }
for ( i = 0; i < packaged.length; i++ ) {
  
    $.writeln( packaged );
   
    }

But it doesn't seem to pick up all the files (only the first three folders get checked)

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 ,
Nov 11, 2016 Nov 11, 2016

Copy link to clipboard

Copied

LATEST

Hello,

Perhaps it' s a problem with file or folder's names.

Your script works fine, but I get empty packaged array when there's no "Links" folder, so iI added : " && Folder(myFiles + "/Links/").exists"

var links = [],

    packaged = [],

    files = [],

    myFolder = Folder( "A:\jake/" ),

    myDocs = [],

    myFiles = myFolder.getFiles();  //store the target files in a variable

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

    if ( myFiles instanceof Folder && Folder(myFiles + "/Links/").exists) {

        packaged.push( Folder(myFiles + "/Links/").getFiles() );

    }

}

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

    //alert( packaged );

    $.writeln( packaged );

}

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