skip to Main Content

I’m using Photoshop script. I get files from folders. My problem is that when I get the files and place them in an array the array contains hidden files that are in the folder for example “.DS_Store”. I can get around this by using:

if (folders[i] != "~/Downloads/start/.DS_Store"){}

But I would like to use something better as I sometimes look in lots of folders and don’t know the “~/Downloads/start/” part.

I tried to use indexOf but Photoshop script does not allow indexOf. Does anybody know of a way to check if “.DS_Store” is in the string “~/Downloads/start/.DS_Store” that works in Photoshop script?

I see this answer but I don’t know how to use it to test: Photoshop script to ignore .ds_store

2

Answers


  1. Chosen as BEST ANSWER

    For anybody looking I used the Polyfill found here:

    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf

    indexOf() was added to the ECMA-262 standard in the 5th edition; as such it may not be present in all browsers. You can work around this by utilizing the following code at the beginning of your scripts. This will allow you to use indexOf() when there is still no native support. This algorithm matches the one specified in ECMA-262, 5th edition, assuming TypeError and Math.abs() have their original values.


  2. For anyone else looking for a solution to this problem, rather than explicitly trying to skip hidden files like .DS_Store, you can use the Folder Object’s getFiles() method and pass an expression to build an array of file types you actually want to open. A simple way to use this method is as follows:

    // this expression will match strings that end with .jpg, .tif, or .psd and ignore the case
    var fileTypes = new RegExp(/.(jpg|tif|psd)$/i);
    
    // declare our path
    var myFolder = new Folder("~/Downloads/start/");
    
    // create array of files utilizing the expression to filter file types
    var myFiles = myFolder.getFiles(fileTypes);
    
    // loop through all the files in our array and do something
    for (i = 0; i < myFiles.length; i++) {
         var fileToOpen = myFiles[i];
         open(fileToOpen);
         // do stuff...
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search