Quantcast
Channel: Adobe Community : Popular Discussions - Photoshop Scripting
Viewing all articles
Browse latest Browse all 12244

Using getFiles() to run quicker: avoiding cleaning for() and getting the right files or folders

$
0
0

Many times i have collected files form a folder using no mask or a file mask like this:

.getFiles() // gets all (also hidden files)

.getFiles('*.jpg') >> all inner jpgs

.getFiles( /\.(DNG?|CR2?)$/i ) >> using RegExp to collect all DNG and CR2 (case insensitive)

.getFiles( function(f) { return f instanceof Folder; }) >> gets only the all the inner folders

.getFiles( function(f) { return f instanceof File; }) >> gets only the all the inner files

 

In the manuals we don't find anything that clarifies this RegExp mask that could be used as argument at .getFiles(mask) function.

For my experience, this has a great importance because getFiles() can't be over used if I want scripts to run fast.

When we over use getFiles() whiteout any mask and then we need to create for routines to remove unwanted files collected it is important to decide if it is possible to avoid it at all.

 

Now, I use also getFiles also to collect specific folders (not files) containing specific letter/number sequences.

 

For example:

 

// This will collect all folders that contains capitals 'SS' or 'AW' or 'CARRYOVER' and that have or have not any number after

var regthis = new RegExp( '(SS|AW|CARRYOVER)(\d?)');

var collectedArr = myFolder.getFiles(regthis);

 

I use a great tool to test any RegExp expression I want to use on any target string:

http://rubular.com/


Viewing all articles
Browse latest Browse all 12244

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>