7 Replies Latest reply on Jan 13, 2011 4:47 PM by Michael L Hale

    Question about error 1242 (File/Folder Expected)

    markerline Level 4

      I have the following code:

       

       

      var myAmount = prompt("How many?");

      var myDir="f/[dirpath]/photoshop_js_test/";

      var myName="testJPEG";

      var mySuffix=".jpg";

      var myFile;

      for (var i = myAmount; i>0; i--){

      myFile=myDir+myName+i+mySuffix;

      var myJPEG = new JPEGSaveOptions();

      myJPEG.quality = 5;

      myJPEG.formatOptions= FormatOptions.STANDARDBASELINE;

      activeDocument.saveAs(myFile, myJPEG, false);

      activeDocument.close();

      var j=i-1;

      var myNewFile=myDir+myName+j+mySuffix;

      open(myNewFile);

      }

       

      But the interpreter gets stuck on this line:

       

      activeDocument.saveAs(myFile, myJPEG, false);

       

      and gives me error 1242 - Illegal argument . . . File/Folder expected.

       

      I'm stumped.  I know little about Javascript and am learning another ECMA script (ActionScript) but I was trying to create code for someone who posted in the Photoshop forum.  I suggested Javascript to him and am now trying to emulate the problem he posted about.

       

      (the [dirpath] is a path on my computer which I commented out with brackets to protect my file system.)

       

      Any help is greatly appreciated.

       

      Sincerely,

      -markerline

        • 1. Re: Question about error 1242 (File/Folder Expected)
          Paul Riggott Level 6

          You are using a string not a File object!

          IE:

          open(myNewFile); you could use

          open(new File(myNewFile));

          activeDocument.saveAs(myFile, myJPEG, false);

          as

          activeDocument.saveAs(new File(myFile), myJPEG, false);

          1 person found this helpful
          • 2. Re: Question about error 1242 (File/Folder Expected)
            markerline Level 4

            Aha, but now I am getting the error 8800: General Photoshop Error occured.  This functionality may not be available in this version of Photoshop.--Could not save as "C:\...\testJPEG5.jpg" because the file could not be found.

            Line 12

            -> activeDocument.saveAs(new File(myFile), myJPEG, false);

             

            I'm wondering why the error message is trying to reference the C partition when I am explicitly calling the F partition in "myDir"?

             

            -markerline

             

            P.S. This is JS not JSX .

             

            Message was edited by: markerline

            • 3. Re: Question about error 1242 (File/Folder Expected)
              Paul Riggott Level 6

              You could try this..

              var myDir="/f/[dirpath]/photoshop_js_test/";

              Note the slash before the disk.

              You can also do a check if the file exist:-

              if(!myFile.exists){

              alert("File does not exist");

              return;

              }

              • 4. Re: Question about error 1242 (File/Folder Expected)
                markerline Level 4

                I now have the following script:

                 

                // from page 146-147, 153
                var myAmount = prompt("How many?");
                var myDir="/f/[dirpath]/photoshop_js_test/";
                var myName="testJPEG";
                var mySuffix=".jpg";
                var myFile;
                var j;
                for (var i = myAmount; i>0; i--){
                myFile=myDir+myName+i+mySuffix;
                var myJPEG = new JPEGSaveOptions();
                myJPEG.quality = 5;
                myJPEG.formatOptions= FormatOptions.STANDARDBASELINE;
                activeDocument.saveAs(new File(myFile), myJPEG, false);
                activeDocument.close();


                var myNewFile=myDir+myName+i+mySuffix;
                open(new File(myNewFile));

                }

                 

                But what I am trying to do is incrementally degrade the picture.  The first picture (since i--) will be the most degraded.  I am trying to show that saving each new JPG with quality less than 12 (which is the maximum you can choose) will degrade the picture more and more.  I did a test with 5 images and all of them looked the same.  Is my script incorrect the way I have it?  Am I referencing the same file each time?  In fact I think I am.  What I need to do is to be able to rewrite the variable for myName within the for loop.  How can I do this?  do I use myName=myName+i?

                • 5. Re: Question about error 1242 (File/Folder Expected)
                  Paul Riggott Level 6

                  It looks as if you are opening the file you have just saved and that's what you are after, maybe Mike or one of the locals can see something. It's getting late here

                  • 6. Re: Question about error 1242 (File/Folder Expected)
                    markerline Level 4

                    Thanks.  Sleep well.  I am grateful for your help thus far.  Indeed I am trying to open the last file that was saved in succession, not the original file each time.  If I do the process manually I can see that each incremental save degrades the image, especially if I use a quality setting of "0" which is very low.  However I cannot seem to get the script to behave the same way as my manual method does. . . .

                    • 7. Re: Question about error 1242 (File/Folder Expected)
                      Michael L Hale Level 5

                      This works for me. Note I had to modify your save path as F on my system is a DVD.

                      var myAmount = prompt("How many?");
                      var myDir="/e/test/";
                      var myName="testJPEG";
                      var mySuffix=".jpg";
                      var myFile;
                      var j;
                      for (var i = myAmount; i>0; i--){
                      myFile=myDir+myName+i+mySuffix;
                      var myJPEG = new JPEGSaveOptions();
                      myJPEG.quality = 5;
                      myJPEG.formatOptions= FormatOptions.STANDARDBASELINE;
                      activeDocument.saveAs(new File(myFile), myJPEG, false);
                      activeDocument.close();
                      
                      
                      var myNewFile=myDir+myName+i+mySuffix;
                      open(new File(myNewFile));
                      
                      }
                      

                      But I would not expect much quality loss by just resaving the file over and over without some editing. The JPEG FAQ says that if you save an unedited file with the same quality setting there will be very little quality loss. http://www.faqs.org/faqs/jpeg-faq/part1/section-10.html paragraph 3