14 Replies Latest reply on Mar 18, 2018 6:51 PM by r-bin

    Unzip a file

    Beracah SB Level 1

      Hi Team,

       

      Is there any possibility of unzipping a file from desktop and execute an action through PS.

        • 1. Re: Unzip a file
          Davide_Barranca Adobe Community Professional

          If you're familiar with command-line zip (see Unzipping Files Using Terminal | Mac Tricks And Tips for info), you can write the needed lines into a string and then pass it to the app.system() function, for instance:

           

          var cmd = "cd ~/Desktop/srcFolder\n" +
                    "unzip -o test.zip -d ~/Desktop/destFolder";
          app.system(cmd);
          

           

          Hope this helps,

          Davide

          2 people found this helpful
          • 2. Re: Unzip a file
            Beracah SB Level 1

            Thanks Davide!

            • 3. Re: Unzip a file
              natrev Level 3

              Hi Davide,

               

              Is this possible to unzip file from sever..? since I used that code and getting error..

               

              var cmd = "cd //NEWSERVER/Source files\n" + "unzip -o test.zip -d ~/Desktop/dest Folder";  
              app.system(cmd);  
              

               

              yajiv

              • 4. Re: Unzip a file
                Davide_Barranca Adobe Community Professional

                Hi Yajiv,

                what about the following?

                 

                var cmd = "unzip -o //NEWSERVER/Source files/test.zip -d ~/Desktop/dest Folder";    
                app.system(cmd);    
                
                • 5. Re: Unzip a file
                  r-bin Level 5

                  Names with spaces must be quoted. For two or more commands, use "cmd / c" and "&".
                  That's how it should work (did not check it).

                   

                  var cmd = "cmd /c cd \"//NEWSERVER/Source files\"" + " & "+ "unzip -o test.zip -d \"~/Desktop/dest Folder\"";
                  app.system(cmd); 
                  
                  • 6. Re: Unzip a file
                    natrev Level 3

                    Hi Davide and r-bin,

                     

                    Thank you for the prompt response and sorry for the late reply.

                    I have tested both code and result is same not working. Kindly advice

                     

                    try{
                    var cmd = "cmd /c cd \"~/Desktop/src Folder\"" + " & "+ "unzip -o Team FP.zip -d \"~/Desktop/dest Folder\"";  
                    app.system(cmd);
                    }catch(er){alert(er)}
                    

                     

                    -yajiv

                    • 7. Re: Unzip a file
                      r-bin Level 5

                      Both commands work (verified)

                       

                      var cmd1 = "unzip -o \"\\\\Server\\Folder\\SubFolder\\a.zip\" -d \"%USERPROFILE%\\Desktop\\dest Folder\""   
                      var cmd2 = "pushd \"\\\\Server\\Folder\\SubFolder\"" + " & unzip -o \"a.zip\" -d \"%USERPROFILE%\\Desktop\\dest Folder\""         
                      
                      app.system(cmd1 + " & pause"); 
                      app.system(cmd2 + " & pause"); 
                      
                      1 person found this helpful
                      • 8. Re: Unzip a file
                        natrev Level 3

                        Hi r-bin,

                         

                        Thank you so much for the script. I have done some modification on existing script and the script working fine.

                        I have changed "/Users/yajiv/Desktop" instead of "~/Desktop"

                         

                            UnzipFiles("/Users/yajiv/Desktop/src Folder/TestFP.zip","/Users/yajiv/Desktop/dest Folder");
                        
                            function UnzipFiles(ZipFile,DestFolder){               
                                var cmd = "unzip \""+File(ZipFile).fsName+"\" -d \""+DestFolder+"\"";          
                                app.system(cmd);
                                var tmpFile=File(DestFolder+"/ticket.xml");     
                                if(tmpFile.exists) tmpFile.remove();
                                var tmpFolder=Folder(DestFolder+"/__MACOSX");        
                                if(tmpFolder.exists) tmpFolder.remove();
                            }
                        

                         

                        You help much appreciated..

                         

                        -yajiv

                        • 9. Re: Unzip a file
                          Kukurykus Adobe Community Professional

                          It does work in cmd.exe:

                           

                          "C:\Program Files (x86)\WinRAR\unrar.exe" x "%USERPROFILE%\Desktop\test.rar"
                          

                           

                          Why it doesn't work in ESTK with targeted Photoshop:

                           

                          system('"C:\\Program Files (x86)\\WinRAR\\unrar.exe" x "%USERPROFILE%\\Desktop\\test.rar"')
                          

                           

                           

                          Moreover I can create bat.bat file that I can run from desktop:

                           

                          cmnd = '"C:\\Program Files (x86)\\WinRAR\\unrar.exe" x "%USERPROFILE%\\Desktop\\test.rar"'
                          fle = File(Folder.desktop + '/bat.bat'), fle.open('w'), fle.write(cmnd), fle.close()
                          

                           

                          But when I add to above code:

                           

                          fle.execute()
                          

                           

                          only bat.bat is created, but not executed :/

                           

                           

                          When bat.bat on desktop is created and then I run from ESTK:

                           

                          File(Folder.desktop + '/bat.bat').execute()
                          

                           

                          it's executed, but cmd.exe acts differently, I mean asks me some questions. Even if I answer for them files are still unrared!

                          • 10. Re: Unzip a file
                            r-bin Level 5

                            Try this

                             

                            var cmd = '"C:\\Program Files (x86)\\WinRAR\\unrar.exe" x "%USERPROFILE%\\Desktop\\test.rar"';  
                            system('"' + cmd + '"')
                            

                             

                            This will extract the files to the current folder. And the current folder is the path to Photoshop.exe. It is necessary to have rights.

                             

                            In the second case, everything is also extracted to the Photoshop folder.

                            Try this

                             

                            cmnd = '"C:\\Program Files (x86)\\WinRAR\\unrar.exe" x "%USERPROFILE%\\Desktop\\test.rar" "%USERPROFILE%\\Desktop"'  
                            fle = File(Folder.desktop + '/bat.bat'), fle.open('w'), fle.write(cmnd), fle.close()  
                            fle.execute() 
                            
                            1 person found this helpful
                            • 11. Re: Unzip a file
                              Kukurykus Adobe Community Professional

                              To be very honest before you posted your solution my last try had to be with additional quotes (so like in your example), as I tried something like it in deep past and it worked, but then looked once again at code and found, no way, that has no sense - it all looks like that should work. So I didn't eventually try that trick. Even if I did I still had problem. Because your first code does not work. It works only when like in second code you posted the destination folder for unrared content is specified so:

                               

                              system('""C:\\Program Files (x86)\\WinRAR\\unrar.exe" x "%USERPROFILE%\\Desktop\\test.rar" "%USERPROFILE%\\Desktop""')
                              

                               

                              That specified destination that should be added at end of code I saw in some exampes I googled, but I did not use that as trying it without it directly from Command Prompt showed it is not needed. Well I thought if in Command Line that is no needed then why that should be used in ESTK. That's not logical for me. THX again that I had no to loose much time on it.

                              • 12. Re: Unzip a file
                                r-bin Level 5

                                At me all works fine and files are extracted in a folder
                                C: \ Program Files \ Adobe \ Adobe Photoshop CS6.
                                I knowingly said about access rights. Or run photoshop with administrator rights

                                • 13. Re: Unzip a file
                                  Kukurykus Adobe Community Professional

                                  Ah I am sorry, I missed that sentence about unraring to Photoshop folder. Yes I checked that, you are right. They were there. But like I found if you want to use system (so no .bat method) to extract your files to specified spot in your system then you can add third path at end of command code (so like in your .bat example). I'm not sure that did work for you, but for me did, and that what I wanted to get

                                  • 14. Re: Unzip a file
                                    r-bin Level 5

                                    By the way, you can play with this

                                     

                                    var comspec = $.getenv("comspec")
                                    alert(comspec)
                                    
                                    $.setenv("comspec", "C:\\Windows\\notepad.exe");
                                    
                                    system("1234")
                                    
                                    $.setenv(somprec); // wrong
                                    

                                     

                                    EDIT:

                                    $.setenv("comspec", comspec) //right
                                    
                                    1 person found this helpful