Skip to main content
siva k
Known Participant
March 2, 2011
Question

Help Need for .zip creation instead of Package folder

  • March 2, 2011
  • 2 replies
  • 3393 views

Hello every one,

I have script for Package creation which was modified by “Mi_D”. Script is working pretty well. It’s creating Package folder in same path. I am looking for small modification in this script. Instead of Package folder I need a .zip file in the same path, kindly help me. I have checked in these forms, scripting guide…etc. but there is no helpful information.

I also checked below link:

http://forums.adobe.com/message/2794194#2794194

var myDocument = app.activeDocument;
var myDocName = myDocument.name;
temp=myDocName.replace(/\.indd/g,"");
var myFileNme=temp.toString();
var myFolder =myDocument.filePath;
var to = new File(myFolder + "/" + myFileNme + "/");
var flag = Folder(to).create();
var copyingFonts = true;
var copyingLinkedGraphics = true;
var copyingProfiles = true;
var updatingGraphics = true;
var includingHiddenLayers = true;
var ignorePreflightErrors = true;
var creatingReport = false;
var versionComments = "comment";
var forceSave = true;
if ( flag === true){
    app.activeDocument.packageForPrint (
          to,
          copyingFonts,
          copyingLinkedGraphics,
          copyingProfiles,
          updatingGraphics,
          includingHiddenLayers,
          ignorePreflightErrors,
          creatingReport,
          versionComments,
          forceSave
         );
}

Thanks in advance.

Regards,

Siva

This topic has been closed for replies.

2 replies

Marc Autret
Legend
March 8, 2011

Hi Siva,

It is quite possible to write from scratch your own ZIP generator in JavaScript, but fortunately you'll find various available libraries on the Internet to facilitate the job! Personaly I've used JSZip as a starting point:

http://jszip.stuartk.co.uk/

(There are only a few adjustments to make it work under ExtendScript.)

@+

Marc

John Hawkinson
Inspiring
March 8, 2011

But why would you want to? It's a big maintenance hassle and the operating system does a perfectly good job of providing a zip tool already.

Siva, are you on a Mac or PC?

Muppet_Mark-QAl63s
Inspiring
March 8, 2011

ditto john…

Mayhem SWE
Inspiring
March 2, 2011

Pretty sure it isn't possible from JavaScript, you will likely need to involve AppleScript (or VBScript if on a PC).

Loic.Aigon
Legend
March 4, 2011

Hi,

As Mayhem suggests, your solution is to call Applescript (Mac) or VB(PC). I don't know how that works in VB but in APS you can do this :

do shell script "zip ..."

where ... are instructions that you can find with : zip -help in the terminal

I don't have any clue how you do it through VB but google can help maybe.

I was told there was a js library for zipping file but never used it.

Hope it helps

Steven__
Inspiring
March 8, 2011

This is Zip code for vb. I did a bad job with copy and paste so there got to be some errors. But the main idea is here.

' Pass path & name to original & zip file

Sub CreateZip(OriginalFile,ZipFile) 

    Set oZipShell = CreateObject("WScript.Shell")    Set oZipFSO = CreateObject("Scripting.FileSystemObject")     If Not oZipFSO.FileExists(ZipFile) Then     NewZip(ZipFile)   Else      Set aFile = oZipFSO.GetFile(ZipFile)      aFile.Delete      NewZip(ZipFile)   End If

  Set oZipApp = CreateObject("Shell.Application")

    sZipFileCount = oZipApp.NameSpace(ZipFile).items.Count   aFileName = Split(OriginalFile, "\")   sFileName = (aFileName(Ubound(aFileName)))     'listfiles   sDupe = False   For Each sFileNameInZip In oZipApp.NameSpace(sZipFile).items     If LCase(sFileName) = LCase(sFileNameInZip) Then       sDupe = True       Exit For     End If   Next     If Not sDupe Then     oZipApp.NameSpace(sZipFile).Copyhere sFile     'Keep script waiting until Compressing is done     On Error Resume Next     sLoop = 0     Do Until sZipFileCount < oZipApp.NameSpace(sZipFile).Items.Count       Wscript.Sleep(100)       sLoop = sLoop + 1     Loop     On Error GoTo 0   End If

End Sub

Sub NewZip(sNewZip)     Set oNewZipFSO = CreateObject("Scripting.FileSystemObject")   Set oNewZipFile = oNewZipFSO.CreateTextFile(sNewZip)       oNewZipFile.Write Chr(80) & Chr(75) & Chr(5) & Chr(6) & String(18, 0)     oNewZipFile.Close   Set oNewZipFSO = Nothing   Wscript.Sleep(500) End Sub