Highlighted

Open graphical file on filename using regEx (photoshop macOS)

New Here ,
Oct 27, 2020

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:

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);
}
Adobe Community Professional
Correct answer by Manan Joshi | Adobe Community Professional

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

TOPICS
Bug, How to

Views

33

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Open graphical file on filename using regEx (photoshop macOS)

New Here ,
Oct 27, 2020

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:

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);
}
Adobe Community Professional
Correct answer by Manan Joshi | Adobe Community Professional

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

TOPICS
Bug, How to

Views

34

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Oct 27, 2020 0
Adobe Community Professional ,
Oct 27, 2020

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 27, 2020 1
Adobe Community Professional ,
Oct 27, 2020

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 27, 2020 0
New Here ,
Oct 27, 2020

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 27, 2020 0
Adobe Community Professional ,
Oct 27, 2020

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 27, 2020 0