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

Open graphical file on filename using regEx (photoshop macOS)

New Here ,
Oct 27, 2020 Oct 27, 2020

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:

var inFolder = new Folder("/Photoshop/ImageData/A3")
if(inFolder != null) {
var fileList = inFolder.getFiles(/^[MSG]{3}.*\.(png|tif|jpg)/);
}
for(var a = 0; a < fileList.length; a++) {
var docRef = open(fileList[a]);
.
.
.
.
 

----------------

for the file name e.g. VIS6_20201009_.tif I use the following:

var inFolder = new Folder("/Photoshop/ImageData/A3")
if(inFolder != null){
var fileList = inFolder.getFiles(/^[VIS]{3}.*\.(png|tif|jpg)/);
}

 

for(var a = 0; a < fileList.length; a++) {
var docRef = open(fileList[a]);
.
.
.
.
 
If I switch and just let one filename type inside the source directory using the following - it works fine.
var inFolder = new Folder("/Photoshop/ImageData/A3")
if(inFolder != null){
var fileList = inFolder.getFiles(/\.(jpg|tif|png|)$/i);
}
296
Translate
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

Community Expert , Oct 27, 2020 Oct 27, 2020

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

Translate
Adobe
Community Expert ,
Oct 27, 2020 Oct 27, 2020

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.

Translate
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 Expert ,
Oct 27, 2020 Oct 27, 2020

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

Translate
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 ,
Oct 27, 2020 Oct 27, 2020

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.

Translate
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 Expert ,
Oct 27, 2020 Oct 27, 2020
LATEST

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

Translate
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