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

Unzip a file

Community Beginner ,
Nov 10, 2017 Nov 10, 2017

Copy link to clipboard

Copied

Hi Team,

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

TOPICS
Actions and scripting

Views

6.3K

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

correct answers 1 Correct answer

Engaged , Nov 11, 2017 Nov 11, 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

Votes

Translate

Translate
Adobe
Engaged ,
Nov 11, 2017 Nov 11, 2017

Copy link to clipboard

Copied

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 author
www.ps-scripting.com

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 Beginner ,
Nov 13, 2017 Nov 13, 2017

Copy link to clipboard

Copied

Thanks Davide!

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 ,
Nov 13, 2017 Nov 13, 2017

Copy link to clipboard

Copied

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

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 ,
Nov 15, 2017 Nov 15, 2017

Copy link to clipboard

Copied

Hi Yajiv,

what about the following?

var cmd = "unzip -o //NEWSERVER/Source files/test.zip -d ~/Desktop/dest Folder";   

app.system(cmd);   

Davide Barranca - PS developer and author
www.ps-scripting.com

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
People's Champ ,
Nov 15, 2017 Nov 15, 2017

Copy link to clipboard

Copied

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

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 ,
Nov 15, 2017 Nov 15, 2017

Copy link to clipboard

Copied

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

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
People's Champ ,
Nov 16, 2017 Nov 16, 2017

Copy link to clipboard

Copied

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

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 ,
Nov 16, 2017 Nov 16, 2017

Copy link to clipboard

Copied

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

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
LEGEND ,
Mar 18, 2018 Mar 18, 2018

Copy link to clipboard

Copied

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!

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
People's Champ ,
Mar 18, 2018 Mar 18, 2018

Copy link to clipboard

Copied

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()

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
LEGEND ,
Mar 18, 2018 Mar 18, 2018

Copy link to clipboard

Copied

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.

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
People's Champ ,
Mar 18, 2018 Mar 18, 2018

Copy link to clipboard

Copied

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

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
LEGEND ,
Mar 18, 2018 Mar 18, 2018

Copy link to clipboard

Copied

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

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
People's Champ ,
Mar 18, 2018 Mar 18, 2018

Copy link to clipboard

Copied

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

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
LEGEND ,
Feb 18, 2021 Feb 18, 2021

Copy link to clipboard

Copied

LATEST

I understand this code. It opens notepad and ask me if I want to save document as \c 1234.txt?

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