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

try and catch to 'ignore read composite data' error

Engaged ,
Jun 05, 2019 Jun 05, 2019

Copy link to clipboard

Copied

Hello everyone,

I have a huge amount of psd files. Some of them are corrupted and can't be opened. I've created this script to:

1. try and open each one of them, if I can open the file then:

> write it to log

> move the file to a new folder     (t stands for "try was executed")

else (if file can't be opened and is corrupted):

> log it to file

the problem that i'm facing is that I have one kind of error that still pop ups even when I've used try and catch:

I am still getting the error: "ignore read composite data"

#target photoshop

var theFolder = Folder.selectDialog("select folder");

var fileandfolderAr = scanSubFolders(theFolder,/\.(psd)$/i);                //var fileandfolderAr = scanSubFolders(topFolder,/\.(jpg|tif|psd|bmp|gif|png|)$/i);

var fileList = fileandfolderAr[0];

var fromFolder = theFolder.fsName + '\\';                            

var t = theFolder.fsName + '\\t\\';

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

{

var Name = fileList.name;

        try

        {

            open(fileList);

            opened_log();

            app.activeDocument.close(SaveOptions.DONOTSAVECHANGES); 

            moveFile(fromFolder,Name,t,Name)

        }

        catch(e)

        {

            error_log();

        }

}

function scanSubFolders(tFolder, mask) { // folder object, RegExp or string

    var sFolders = new Array();

    var allFiles = new Array();

    sFolders[0] = tFolder;

    for (var j = 0; j < sFolders.length; j++){ // loop through folders           

        var procFiles = sFolders.getFiles();

        for (var i=0;i<procFiles.length;i++){ // loop through this folder contents

            if (procFiles instanceof File ){

                if(mask==undefined) allFiles.push(procFiles);// if no search mask collect all files

                if (procFiles.fullName.search(mask) != -1) allFiles.push(procFiles); // otherwise only those that match mask

        }else if (procFiles instanceof Folder){

            sFolders.push(procFiles);// store the subfolder

            scanSubFolders(procFiles, mask);// search the subfolder

         }

      }

   }

   return [allFiles,sFolders];

};

function moveFile(fromFolder,fileName,toFolder,newName)

  retcode = false; 

  if(!(new Folder(toFolder)).exists){ new Folder(toFolder).create();} 

  if(!(new Folder(toFolder)).exists){ alert("Folder " + toFolder + " could not be created.");} 

  else { 

      if (new File(fromFolder + fileName).exists){ 

     

         //if (app.systemInformation.indexOf("Operating System: Windows") >= 0)

         app.system('Move /Y "' + fromFolder + fileName + '"  "' + toFolder + newName + '"'  );     //will overwrite with /Y without prompt 

     

         for (var i=0;i<100000;i++) { if (!(new File(fromFolder + fileName).exists)) break; } //give it some time 

         if (newName=="") {newName = fileName;}

         if (!(new File(fromFolder + fileName).exists) && (new File(toFolder + newName).exists))  retcode = true; 

     }  

     else {alert("File " + fromFolder + fileName + " does not exists");} 

  } 

  return retcode; 

function error_log()

{

    if(documents.length)

    {

       

                        var doc = activeDocument;

                        var a,b,c,d ="";

                        // Name without file extension

                        var Name = doc.name;

                        if (Name.indexOf(".") != -1 ) Name=Name.substr(0,Name.lastIndexOf("."));

                        //

                        var log = File(Folder.desktop + "/" + "error log.csv");                //var log = File(Folder.desktop + "/" + Name + ".csv");

                        log.open("a");

                        a=decodeURI(doc.name);

                        //b=decodeURI(doc.path.fsName);

                        var today = new Date();

                        var todayDay = today.getDate();

                        if (todayDay < 10)

                        {

                            todayDay = "0" + todayDay;

                        }

                        var todayMonth = today.getMonth()+1;

                        if (todayMonth < 10)

                        {

                            todayMonth = "0" + todayMonth;

                        }

                        var todayYear = today.getFullYear();

                        var todayDate = todayDay+'-'+todayMonth+'-'+todayYear;

                        var todayTime = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();

                        var todayDate_Time = todayDate + " " + todayTime;

                        log.writeln(todayDate_Time + "," + a);

                       

                        log.close();

                       

    }

}

function opened_log()

{

    if(documents.length)

    {

       

                        var doc = activeDocument;

                        var a,b,c,d ="";

                        // Name without file extension

                        var Name = doc.name;

                        if (Name.indexOf(".") != -1 ) Name=Name.substr(0,Name.lastIndexOf("."));

                        //

                        var log = File(Folder.desktop + "/" + "opened log.csv");                //var log = File(Folder.desktop + "/" + Name + ".csv");

                        log.open("a");

                        a=decodeURI(doc.name);

                        b=decodeURI(doc.path.fsName);

                        var today = new Date();

                        var todayDay = today.getDate();

                        if (todayDay < 10)

                        {

                            todayDay = "0" + todayDay;

                        }

                        var todayMonth = today.getMonth()+1;

                        if (todayMonth < 10)

                        {

                            todayMonth = "0" + todayMonth;

                        }

                        var todayYear = today.getFullYear();

                        var todayDate = todayDay+'-'+todayMonth+'-'+todayYear;

                        var todayTime = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();

                        var todayDate_Time = todayDate + " " + todayTime;

                        log.writeln(todayDate_Time + "," + a +"," + b);

                       

                        log.close();

                       

    }

}

TOPICS
Actions and scripting

Views

2.6K

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
community guidelines
Adobe
Community Expert ,
Jun 05, 2019 Jun 05, 2019

Copy link to clipboard

Copied

Is that a Popup actually a dialog  to allows you to ignore and open the layered document anyway  is there an option not to ignore the problem.  Does the popup have two option is it a dialog. Where one will get the file move and the other will log the the file as corrupt. There may be a compatibility issue with the version of Photoshop trying to open a document save be a newer version of Photoshop,   It sounds like it may be offering to use the Layer composite rather then the layer that has some feature the running version of Photoshop does not support.

JJMack

Votes

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
community guidelines
Engaged ,
Jun 05, 2019 Jun 05, 2019

Copy link to clipboard

Copied

this is the error that pops up:

Capture.JPG

I have 50000 files that i need to check, I can't have any kind of pop up to interrupt, that's why i used try and catch, which still haven't worked

Votes

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
community guidelines
Community Expert ,
Jun 05, 2019 Jun 05, 2019

Copy link to clipboard

Copied

Perhaps if you run your script  from the most current Photoshop version you may not have many compatibility issues.  Still there may be compatibility issues.  Adobe dose not always maintain backwards compatibility.  

You would need to have Adobe add a Photoshop  preference the would consider all compatibility issues an error  you script would then receive and error and  not enter into an interactive dialog.

Currently there is no such prference.

JJMack

Votes

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
community guidelines
Engaged ,
Jun 05, 2019 Jun 05, 2019

Copy link to clipboard

Copied

that's a good point, I do run photoshop 2018 CC on that machine.

I will install latest version and try again

Votes

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
community guidelines
Guest
Jun 07, 2019 Jun 07, 2019

Copy link to clipboard

Copied

app.displayDialogs =DialogMOdes.NO;

Votes

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
community guidelines
Community Expert ,
Jun 07, 2019 Jun 07, 2019

Copy link to clipboard

Copied

知鱼之乐  wrote

app.displayDialogs =DialogMOdes.NO;

If that prevent the dialog

Capture.JPG

How will Photoshop behave. Will  it read the composite data or, cancel the open or, through an error.  If an error is thrown and the script ignores it will the file be opened or not. How can a script deal with compatibility issues?

JJMack

Votes

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
community guidelines
Engaged ,
Jun 10, 2019 Jun 10, 2019

Copy link to clipboard

Copied

I've tried:

app.displayDialogs =DialogModes.NO;

not working

I've also updated to the latest version of Photoshop, not working also.

Please any ideas what to do next?

Votes

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
community guidelines
Community Expert ,
Jun 10, 2019 Jun 10, 2019

Copy link to clipboard

Copied

I did not think that it would.   You see it is not an actual programing error its  a program seeing that there is a compatibility issue. Photoshop is offering you option for handling the compatibility issue.  I know of no preference that will change Photoshop Open File operation to consider compatibility issues an error..

As for scripting  I see two DOM  methods to open image files.

Photoshop DOM Method Load will also load image documents but has options. Photoshop DOM Open method has options but none are for forcing comparability issues be an error.  The options are only for specific Images file types.  These  types are more imported into Photoshop then opened into Photoshop.  For Photoshop may not fully support the File format full specifications. In Photoshop they will be a raster images layer not actually the file opened into Photoshop more a file conversion then the actual file.  Like Photoshop can not save a camera RAW File Format and  EPS vector Object are not not vector graphics in Photoshop.  Photoshop File Formats support is a mixed bag a melting pot. For example  A placed .svg file will be a "vector smart object layer"  While there are no vector in Photoshop there are vectors in the object's file object and if you scale the smart object layer Photoshop will replace the object a different size object using vector graphics by reprocessing the object .svg file object.  However if you open the same SVG file into  Photoshop it will imported the image as a raster layer and will scale be scaled as such via interpolation for there will be no vectors in Photoshop at all and if you change the image and export it as an svg file the will be no vectors in that svg file how coult the be.

JJMack

Votes

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
community guidelines
Engaged ,
Jun 10, 2019 Jun 10, 2019

Copy link to clipboard

Copied

I think I will run a windows automation macro while the photoshop script running. The macro will click Cancel if it sees the error message pops, and then it will continue. I will check if it works now and what is written in the logs when I click Cancel.

Votes

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
community guidelines
Community Expert ,
Jun 10, 2019 Jun 10, 2019

Copy link to clipboard

Copied

Let us know if that work for you. If it does please post what you used to run the windows automation macro and what the macro look like. That may help others windows user with their automation of Photoshop.  Post that information in this thread...  Good luck.

JJMack

Votes

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
community guidelines
Community Expert ,
Jun 10, 2019 Jun 10, 2019

Copy link to clipboard

Copied

Have you tried to record opening one of these files with scriptListener and using that code to open the files rather than the DOM? It might have code that handles that message.

Votes

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
community guidelines
Engaged ,
Jun 10, 2019 Jun 10, 2019

Copy link to clipboard

Copied

I haven't tried ScriptListener yet, I will try.

Votes

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
community guidelines
Community Expert ,
Jun 10, 2019 Jun 10, 2019

Copy link to clipboard

Copied

As far as I see the will not work, And you you mat also need to check for additional Dialogs in your windows  automation script.  For example I just save a layer with two drop shadow in its layer style in CC 2019.  Close CC 2019 and open cs6.  Captured the action manager code generated for the Open where I replied Keep keep for the compatibility issue.  Had a different Dialog the your dialog.  The capture code has no  information about my reply and  capture code displayed the same compatibility dialog during open as Phoyoshop UI.

Capture.jpg

JJMack

Votes

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
community guidelines
Engaged ,
Jun 10, 2019 Jun 10, 2019

Copy link to clipboard

Copied

i don't have CS6.

will it help if i shared 3 psd files: one with "end-of-file" error, one with "Read composite data" error, and one that is ok, and we'll try using my code + ScriptListener to make it work?

Votes

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
community guidelines
Community Expert ,
Jun 10, 2019 Jun 10, 2019

Copy link to clipboard

Copied

LATEST

What version of Photoshop are you running you script in.  I do not believe Action Manager code will help you like it would to for save as  where Photoshop displays a dialog asking if you want to save over the existing file.  I also do not believe that the Dialog you get will be the only compatibility issue dialog you will encounter.  The version of Photoshop  I currently has installed are CS3, CS6, CC 2014, CC 2018 and CC 2019...

JJMack

Votes

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
community guidelines