Photoshop 脚本 .DS_Store

Photoshop script .DS_Store

我正在使用 Photoshop 脚本。我从文件夹中获取文件。我的问题是,当我获取文件并将它们放在一个数组中时,该数组包含文件夹中的隐藏文件,例如“.DS_Store”。我可以通过使用来解决这个问题:

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

但我想使用更好的东西,因为我有时会查看很多文件夹,但不知道“~/Downloads/start/”部分。

我尝试使用 indexOf,但 Photoshop 脚本不允许使用 indexOf。有人知道检查“.DS_Store”是否在 Photoshop 脚本中有效的字符串“~/Downloads/start/.DS_Store”中的方法吗?

我看到了这个答案,但我不知道如何用它来测试:Photoshop script to ignore .ds_store

对于任何人来说,我使用了在这里找到的 Polyfill:

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.

对于寻找此问题解决方案的任何其他人,而不是明确尝试跳过像 .DS_Store 这样的隐藏文件,您可以使用文件夹对象的 getFiles() 方法并传递一个表达式来构建一个数组您实际想要打开的文件类型。该方法的简单使用方法如下:

// 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...
}