Copy link to clipboard
Copied
Hello Community,
I try to open some files with two different filenames but same suffix(.tif). I need to run different actions to process the images, so I planned to use a regEx to open the needed files. If I run it on windows machine, Photoshop is working well and open the files vise versa if I try to run it on macOS, it seem that the files are not recognized and photoshop is doing nothing (no script error message).
Below you find the start of my script with the location and open the file...
for the filename e.g. MSG3-20201009_.tif I use the following:
----------------
for the file name e.g. VIS6_20201009_.tif I use the following:
1 Correct answer
Try the following
var inFolder = new Folder("/Photoshop/ImageData/A3")
if(inFolder != null) {
var fileList = inFolder.getFiles(function(f){
if(f.name.match(/^[MSG]{3}.*\.(png|tif|jpg)/))
return true
})
}
for(var a = 0; a < fileList.length; a++)
var docRef = open(fileList[a]);
-Manan
Explore related tutorials & articles
Copy link to clipboard
Copied
I've moved this from the Using the Community forum (which is the forum for issues using the forums) to the Photoshop forum so that proper help can be offered.
Copy link to clipboard
Copied
Try the following
var inFolder = new Folder("/Photoshop/ImageData/A3")
if(inFolder != null) {
var fileList = inFolder.getFiles(function(f){
if(f.name.match(/^[MSG]{3}.*\.(png|tif|jpg)/))
return true
})
}
for(var a = 0; a < fileList.length; a++)
var docRef = open(fileList[a]);
-Manan
Copy link to clipboard
Copied
Dear Manan,
Thank you so much, it works!
Looks like it need the 'true' when running photoshop on macOS. As I said on windows it just worked perferct the way I mentioned. I tried playing around with the match() but had no idea how to use it.
Thank you again for teh fast help.
Copy link to clipboard
Copied
On Windows, it seems that the regex is being matched as the filter to the getFiles method on MAC it is not. match is just a method that matches the regex against the string on which the method is called. getfiles can take as an argument a method that returns true for a file/folder that is to be included in the result, so I used this method. I hope this explains everything about my approach to the problem
-Manan

