Quantcast
Channel: Adobe Community : Popular Discussions - Photoshop Scripting
Viewing all articles
Browse latest Browse all 12244

cannot open the file because the open options are incorrect

$
0
0
I'm trying to iterate through a folder of images, open each one of them, duplicate them into another photoshop file and close the individual image. This code works great on a PC (Photoshop CS3), but when I run it on our macs (Photoshop CS3) I will receive the following error on random images. "Error: Cannot open the file because the open options are incorrect" Does anyone know how to solve this problem? I've read about possibly setting the OpenDocumentType but have not seen an example anywhere. This error will sometimes occur after loading in one image or sometimes after 20 images. Sometimes I run it on the same directory multiple times all with various points of error. Sometimes every images is loaded. Any help would be much appreciated. Sample code is below.

i //CODE BELOW

i //allows the user to select an folder full of images

b var inputFolder = Folder.selectDialog("Select a folder that contains the files you want added as layers.");

b var fileList = inputFolder.getFiles();

b var tempRef = app.open(tempName);

b for (var i = 0; i < fileList.length; i++)

b {

b var tempName = fileList[i];

b var tempStringName = fileList[i].toString();

i //used to check if the file in the directory does in fact contain the .png extension

b var reducedFileName = tempStringName.substring(tempStringName.lastIndexOf("/")+1);

b if(reducedFileName.substring((reducedFileName.length - 4),(reducedFileName.length)) != ".png" || reducedFileName.substring((reducedFileName.length - 4),(reducedFileName.length)) != ".PNG")

b {

i //setting reference to opened docuement PNG file

i //This seems to be the section throwing the error. Surrounding with Try Catch revealse the Error noted above

b var tempRef = app.open(tempName);

i //setting a tempName variable to the PNG file name

b var tempName = app.activeDocument.name;

i //setting reference to the active layer in the file

b var graphicLayer = app.activeDocument.activeLayer;

i //setting the PNG layer name to the PNG file

b tempRef.layers[0].name = tempName;

i //duplicating the image onto the opened Photoshop file

b tempRef.layers[0].duplicate(backRef);

i //closing the original PNG file without saving

b tempRef.close(SaveOptions.DONOTSAVECHANGES);

b }

b }

Viewing all articles
Browse latest Browse all 12244

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>