7 Replies Latest reply on Oct 27, 2013 9:53 AM by TᴀW

    Find sibling file not working on Mac

    TᴀW Adobe Community Professional & MVP

      Hi,

       

      Imagine I've got a folder on my desktop containing 2 files. One is called "File1.1.1.jsx", and the other is called "File2.2.2.jsx".

       

      I want the first file to get a handle on the second file. So the first file ("File1.1.1.jsx") contains the following script

       

      #target estoolkit
       var otherFile = new File("File2.2.2.jsx");
       alert (otherFile.exists);
      

       

      On Windows this works fine, and the alert shows "true".

       

      On Mac, though, the alert shows "false", so somebody has told me.

       

      I don't know why. I don't have a Mac to test this on. Can anyone explain to me what's going on? Why is this working on Windows and not Mac?

       

      Thanks,

      Ariel

        • 1. Re: Find sibling file not working on Mac
          pixxxel schubser Level 5

          [Ariel] schrieb:

           

          Hi,

           

          Imagine I've got a folder on my desktop containing 2 files. One is called "File1.1.1.jsx", and the other is called "File2.2.2.jsx".

           

          I want the first file to get a handle on the second file. So the first file ("File1.1.1.jsx") contains the following script

           

          #target estoolkit
           var otherFile = new File("File2.2.2.jsx");
           alert (otherFile.exists);
          

           

          On Windows this works fine, and the alert shows "true".

           

          On Mac, though, the alert shows "false", so somebody has told me.

           

          I don't know why. I don't have a Mac to test this on. Can anyone explain to me what's going on? Why is this working on Windows and not Mac?

           

          Thanks,

          Ariel

           

           

          IMHO I don't think, this can work on Windows.

          If any, then you need a file path to your file like:

           

          #target estoolkit
          var otherFile = new File ("~/Desktop/TestFolder/File2.2.2.jsx");
          alert (otherFile.exists);
          

           

          And I never use a file name like 2.2.2.jsx   Never, never!

          Better is 222.jsx or 2_2_2.jsx

          • 2. Re: Find sibling file not working on Mac
            TᴀW Adobe Community Professional & MVP

            Hi,

             

            Thanks. It does work on Windows. It is not necessary to add the path for

            files that are in the same folder as the script that is being run.

             

            My question is why does it not work on Mac?

             

            Ariel

            • 3. Re: Find sibling file not working on Mac
              Pickory Level 3

              Hello,

               

              I don't know why it works on Windows, I can confirm it does NOT work on Mac.

               

              I have always used some code borrowed from FindChangeByList.

               

              function myFindFile(myFilePath){

                        var myScriptFile = myGetScriptPath();

                        var myScriptFile = File(myScriptFile);

                        var myScriptFolder = myScriptFile.path;

                        myFilePath = myScriptFolder + myFilePath;

                        if(File(myFilePath).exists == false){

                                  //Display a dialog.

                                  myFilePath = File.openDialog("Choose the file containing your find/change list");

                        }

                        return myFilePath;

              }

              function myGetScriptPath(){

                        try{

                                  myFile = app.activeScript;

                        }

                        catch(myError){

                                  myFile = myError.fileName;

                        }

                        return myFile;

              }

               

               

              P.

              1 person found this helpful
              • 4. Re: Find sibling file not working on Mac
                pixxxel schubser Level 5

                Sorry, your way doesn't work on Windows:

                File111.png

                 

                [Ariel] schrieb:

                 

                Hi,

                 

                Thanks. It does work on Windows. It is not necessary to add the path for

                files that are in the same folder as the script that is being run …

                 

                 

                 

                 

                and with a path it works correctly on my Windows:

                 

                File111_true.png

                 

                What are you doing differently?


                Does your script snippet really run standalone?

                1 person found this helpful
                • 5. Re: Find sibling file not working on Mac
                  TᴀW Adobe Community Professional & MVP

                  Strange, pixxxel. It definitely works for me on Windows. But I see that it's not working for you. Not sure why. But anyway, it doesn't matter. Pickory has pointed me in the right direction.

                   

                  This should always work to get the sibling of the active script file:

                   

                  #target estoolkit

                  otherFile = new File((Folder(app.activeScript).parent)+"/File1.1.1.txt");

                  alert(myFile.exists);

                   

                  Thanks both. I think this solves my prob (without delving into the details of why it was or wasn't working before).

                   

                  Ariel

                  • 6. Re: Find sibling file not working on Mac
                    pixxxel schubser Level 5

                    My pleasure.

                     

                     

                    Does this variant also works for you correctly?

                     

                    #target estoolkit
                    
                    var otherFile = File(File($.fileName).parent.fullName +"/File1.1.1.txt");
                    alert (otherFile.exists);