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

Creating a ZIP file

Advocate ,
Apr 21, 2019 Apr 21, 2019

Copy link to clipboard

Copied

Has anyone created a ZIP file via scripting - or even via a batch file on Windows 10 ?

TOPICS
Scripting

Views

8.1K

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

Enthusiast , May 14, 2019 May 14, 2019

I have it working as follows:

Extend script must write two files the first is the bat file which contains the following:

PowerShell -ExecutionPolicy Bypass -File "C:\path_as_required\zipTest.ps1"

The second file is the PowerShell script which for example can be written to compress a folder or many individual files:

Compress-Archive -Path "D:\Support\CGM" -DestinationPath "D:\Support\CGMzip.zip"

This works without any annoying warnings because of the ExecutionPolicy Bypass.

I hope it works for you too!

...

Votes

Translate

Translate
Enthusiast ,
Apr 21, 2019 Apr 21, 2019

Copy link to clipboard

Copied

Hi Jang,

I create zipfiles using a one-line batchfile with 7-Zip:

Zip.bat

Looks like:

"C:\Program Files\7-Zip\7z.exe" a "MyFiles.zip" @Content.txt

That calls 7zip.exe (you need whole path), creates the file MyFiles.zip and uses a text file with a list of files and folders.

Content.txt:

Folder1

Folder2

Folder3

Script1.jsxbin

Script2.jsxbin

Script3.jsxbin

HowToInstall.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
Advocate ,
Apr 22, 2019 Apr 22, 2019

Copy link to clipboard

Copied

OK, I found a method now that should work on any Windows machine, using a batch file that calls a vbs script, which in turn uses a call to a standard zipping library that only has the dot net interface.

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
Advocate ,
May 13, 2019 May 13, 2019

Copy link to clipboard

Copied

I finally found time to start finishing this job. I got the batch file in place but there is a problem with access rights. When I run the batch from the command prompt or from Windows Explorer, it works fine. When I call it via the File.execute( ) function it throws an error.

The batch file uses a VBS to create the ZIP. I guess the VBS is so dangerous that you cannot run it from a batch file. So I will have to look at downloading an exe for zipping after all.

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
Enthusiast ,
May 13, 2019 May 13, 2019

Copy link to clipboard

Copied

Hi Jang,

for a while I was working with this : https://nsis.sourceforge.io/Download

https://nsis.sourceforge.io/Download

Now I'm working the way I described above, copying the files to my user folder before.

But this nullsoft solution is a very good thing!

Have a look at it. There are some examples you can copy and change.

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
Advocate ,
May 13, 2019 May 13, 2019

Copy link to clipboard

Copied

Klaus, how are you getting around Windows exaggerated security issues? I can execute the batch when double-clicking it, I can execute the zip command when running it in the command line, but I cannot execute the batch file from ExtendScript.

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
Enthusiast ,
May 13, 2019 May 13, 2019

Copy link to clipboard

Copied

I was testing a long time until I gave up.

The only way is, to use your own personal folder.

All my scripts at customers side are copied to C:\Users\<USERNAME>\AppData\Roaming\Adobe\FrameMaker\number

There I create a folder "4xscripts" to copy my scripts there.

There the rights are granted.

This way I can claim, that no rights will be violated.

Otherwise, I think, admins have to change the folder rights. And that is to heavy and complex. (The point where I gave up ;-)) )

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
Advocate ,
May 13, 2019 May 13, 2019

Copy link to clipboard

Copied

Yes, I have been putting all my scripts in the AppData area for a long time. But I need to create a ZIP to be uploaded somewhere and there is no way I can move all the company documents into an AppData of a single user.

I guess I will have to find a way around this idiocy that is called MicroSucks.

(frustrated after spending hours of trials and getting nowhere)

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
Enthusiast ,
May 13, 2019 May 13, 2019

Copy link to clipboard

Copied

My thoughts are with you.

I've not strugggeld for hours, but for days. Just try that nullsoft software. It takes some time to know it. It creates self extracting exe-files.

But that could be the next problem, when customer users are not allowed to install software that isn't approved by IT people

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
Enthusiast ,
May 13, 2019 May 13, 2019

Copy link to clipboard

Copied

My next thought: Have you tried running the batch file as administrator?

I'm to tired to create an example by myself. I'll try it tomorrow.

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
Advocate ,
May 13, 2019 May 13, 2019

Copy link to clipboard

Copied

This is not a solution, as normal users have to use my app to create a Zip (not a self-extracting one) to upload to a server. No need to test this as it will not solve anything. Thanks for offering.

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
Enthusiast ,
May 13, 2019 May 13, 2019

Copy link to clipboard

Copied

How you tried a batch file that runs in Windows PowerShell? I seem to remember that PowerShell has a compress archive command.

Ian

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
Advocate ,
May 13, 2019 May 13, 2019

Copy link to clipboard

Copied

How do I run a WIndows PowerShell ? The only option I have is use File.execute( ). I can create a batch file and execute it that way. I cannot hand any arguments to the execute( ) function - or I would not have needed a batch file at all.

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
Enthusiast ,
May 13, 2019 May 13, 2019

Copy link to clipboard

Copied

Generate a text file. Add the commands as required then save it with a .ps1 extension. Then execute this new batch file.

I've not tried it yet, but it could work...

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
Enthusiast ,
May 13, 2019 May 13, 2019

Copy link to clipboard

Copied

One problem is that the default action for a PowerShell script is to open the file for editing...

The compress-archive syntax: Compress-Archive

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
Advocate ,
May 13, 2019 May 13, 2019

Copy link to clipboard

Copied

The other problem is that Windows finds it necessary to bring this stupid "are you sure you want to run such a horribly unsafe program on your computer' EVERY SINGLE TIME. I do hate Windows so much. Why on earth did everyone fall for that crappy system? Oh wait, I know, it was CHEAPER !!!!!

Penny wise and pound foolish. Short-sighted stupid business managers are ruling the planet.

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 ,
May 13, 2019 May 13, 2019

Copy link to clipboard

Copied

Jang,

Maybe this link helps…

powershell - Ignore 'Security Warning' running script from command line - Stack Overflow

Anything is about security. If you write an FDK Plugin, you won't have to care about that.

Why not writing a Plugin? O wait, I know it, ES is CHEAPER!!! (#scnr)

Hope this helps?

Markus

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
Advocate ,
May 14, 2019 May 14, 2019

Copy link to clipboard

Copied

Thanks, I have been trying to get a PowerShell to run without throwing all the dialogs. So far no dice.

About creating an FDK plugin: that is complete overkill for most of the projects as it requires getting friendly with Microsoft's constantly changing Visual Studio and the intricacies of C++. Also, I would have to maintain a different VS version for each FM version as MS tends to change their entire framework every couple of years and have never understood what it means to be backward - or anyward - compatible.

What would help is is someone (Adobe dev team or maybe you) would create a simple straightforward little FDK Client that can ZIP a bunch of files (and maybe also throw in the unzip function while you're at it) and makes it available through the CallClient method in ESTK. Combining the best of both worlds.

Kind regards

Jang

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 ,
May 14, 2019 May 14, 2019

Copy link to clipboard

Copied

Hi Jang,

glad you manged to get this stuff working.

My point of view is, that ES is for easy to not that complex use cases. If zipping is an issue, it's a complex issue, where ESTK is not designed for. So developing plugins is my choice for such use cases.

But please don't complain about things or 3rd parties like Microsoft, which do their Job. And they do, perhaps not with your use cases, but thats not Microsoft's problem. Executing a script by another program, especially JavaScript, is a security issue Microsoft (and others) has to care about.

But let's get more constructive, and Maybe adobe is listening. So we need in ESTK:

- As zipping is getting a common use case more and more, this should be captured by ESTK and FDK, to get easy access to this functionality for anyone.

- possibilites to execute application with Parameters (File.execute doesn't support parameters)

- access to system resources like the Registry

- possibilities for XSLT Transformation outside of the FM Environment (native XML to anything)

I think it's a job for Adobe (if they want to) not for the community to provide such functionality. It has to be integrated for anyone, and not in a plugin developers have to know that this is existing.

Bye

Markus

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
Advocate ,
May 14, 2019 May 14, 2019

Copy link to clipboard

Copied

No, I did not get it working, even after trying all the variants I found on StackOverflow. PowerShell sounds good but is a horror when trying to call it from a batch file.

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 ,
May 14, 2019 May 14, 2019

Copy link to clipboard

Copied

Could you send the powerscript and it's call in ES by PM?

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
Enthusiast ,
May 14, 2019 May 14, 2019

Copy link to clipboard

Copied

I have it working as follows:

Extend script must write two files the first is the bat file which contains the following:

PowerShell -ExecutionPolicy Bypass -File "C:\path_as_required\zipTest.ps1"

The second file is the PowerShell script which for example can be written to compress a folder or many individual files:

Compress-Archive -Path "D:\Support\CGM" -DestinationPath "D:\Support\CGMzip.zip"

This works without any annoying warnings because of the ExecutionPolicy Bypass.

I hope it works for you too!

Ian

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
Advocate ,
May 14, 2019 May 14, 2019

Copy link to clipboard

Copied

That looks a lot simpler than a bunch of posts about PowerShell that I found on the world wide wacky web. I will give it a try and will let you know if I get the required result on my end.

Thanks

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
Enthusiast ,
May 14, 2019 May 14, 2019

Copy link to clipboard

Copied

In the PowerShell script the Path parameter can take a comma separated array of separate files or folders.

It may be useful to add an exit command to the batch file to close command window. 

There's also an Expand-Archive command that unpacks an existing archive.

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 ,
May 14, 2019 May 14, 2019

Copy link to clipboard

Copied

Jang,

as discussed by mail I made a small sample script, which is available here (http://practice-innovation.de/Downloads/call_powershell_script.zip​) (link is not persistent, so hurry up ;-))

You need to create the batch file in your ES and when written, call it with File.execute().

(dynamic Batch is necessary, as you can’t pass parameters to File.execute())

PowerShell-Script takes two parameters (Source-Directory and Zip-FileName). Make sure ZIP files doesn’t exist, before calling the batch, otherwise script throws an error.

Hope this helps

Markus

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