Skip to main content
Shine BR
Known Participant
November 11, 2017
Answered

Unzip a file

  • November 11, 2017
  • 1 reply
  • 7521 views

Hi Team,

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

Correct answer Davide_Barranca12040269

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

1 reply

Davide_Barranca12040269
Legend
November 12, 2017

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

Davide Barranca - PS developer and authorwww.ps-scripting.com
natrev
Legend
November 13, 2017

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

Kukurykus
Legend
March 18, 2018

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");


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!