TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: kenkrupa on March 09, 2011, 08:43:01 PM

Title: Unzip a file programmatically?
Post by: kenkrupa on March 09, 2011, 08:43:01 PM
Any way to unzip a file programmatically (from AutoCAD, using LISP)?
Title: Re: Unzip a file programmatically?
Post by: CAB on March 09, 2011, 10:34:40 PM
These should help:

http://www.pkware.com/software/developer-tools/sdk

http://www.7-zip.org/

http://www.camunzip.com/
  Command line interface exposes all features and options.

One more possibility:

JustZIPit - ZIP Software
Just flat-out the easiest ZIP program!

JustZIPit simplifies ZIP and UnZIP compression all the way! Discarding all clunky interfaces completely, JustZIPit simply ZIPs and unZIPs -- all with one click from the context menu. A powerful ZIP engine with fast full automatic implementation of ZIP-64 for HUGE file support -- which means JustZIPit is among the most powerful ZIP tools at any price -- good thing it's free!

JustZIPit just does ZIP and does it very well - no fluff, no confusion. No more annoying ZIP interfaces -- JustZIPit and go!
Title: Re: Unzip a file programmatically?
Post by: Kerry on March 10, 2011, 12:38:25 AM
Have a play with something like this.

Code: [Select]
(defun ExtractFilesFromZip
       (zipFileName Destination / File Filelist Folder Fso Index Items Path)
  ;;CodeHimBelonga kdub@theSwamp
  ;;
  (setq filelist '()
        Path     (car (fnsplitl zipFileName))
        Fso      (vlax-create-object "Shell.Application")
        Folder   (vlax-invoke fso 'NameSpace zipFileName)
        Items    (vlax-invoke Folder 'Items)
        Index    0
  )
  (repeat (vlax-get-property Items 'Count)
    (setq File     (vlax-invoke Items 'Item Index)
          Filelist (append FileList (list (vlax-get-property File 'Name)))
          Index    (1+ Index)
    )
  )
  (setq Folder (vlax-invoke Fso 'NameSpace Destination)
        Index  0
  )
  (repeat (length FileList)
    (vlax-invoke Folder
                 'CopyHere
                 (strcat zipFileName "\\" (nth Index FileList))
    )
    (setq Index (1+ Index))
  )
  (vlax-release-object Folder)
  (vlax-release-object Items)
  (vlax-release-object Fso)
  Index
)
(princ)



Code: [Select]

(setq return (ExtractFilesFromZip "K:\\KDUBPro2010\\SOURCE\\MISC TOOLS\\TestFile.zip" "K:\\ToTest\\Scrap"))
(alert (strcat (itoa return) " Files Unzipped."))
Title: Re: Unzip a file programmatically?
Post by: Mark on March 10, 2011, 08:50:22 AM
Have a play with something like this.
Sweet!
Title: Re: Unzip a file programmatically?
Post by: kenkrupa on March 10, 2011, 09:41:16 AM
Have a play with something like this.

Excellent! Thank you very much Kerry!
That was worth a donation to theSwamp (and thanks to CAB for that suggestion)
Title: Re: Unzip a file programmatically?
Post by: Kerry on March 10, 2011, 03:21:11 PM

You're most welcome Ken :)


And I'm sure Mark will be able to put your donation to good use.
Title: Re: Unzip a file programmatically?
Post by: Matt__W on March 10, 2011, 03:26:13 PM
When a file comes along, you must ZIP it...
   Now ZIP it... ZIP it good...
Title: Re: Unzip a file programmatically?
Post by: kenkrupa on March 10, 2011, 04:11:49 PM
Doh! - Ran into a couple of unexpected snags. I'm being asked if I want to replace each existing file (I do, without question). Also, one folder I want to unzip to is a subfolder of C:\Program Files, so I'm getting asked for permission for each file (Win7).  Any tricks to overcome either or both or these? If not, I need to do some re-thinking.
Title: Re: Unzip a file programmatically?
Post by: Kerry on March 10, 2011, 04:40:27 PM
Ken,
I don't use Program Files for Data Storage so this issue hasn't arisen for me.
The user will also be asked to confirm file overwrite if files exist, which I'm happy about .... I havn't tried to change this behaviour

update:
I just shared a specific folder in Program Files (Win 7 x64) and unzipped to it. Does that help ?

(setq return (ExtractFilesFromZip "K:\\KDUBPro2010\\SOURCE\\MISC TOOLS\\TestFile.zip" "C:\\Program Files\\_a"))
(alert (strcat (itoa return) " Files Unzipped."))
Title: Re: Unzip a file programmatically?
Post by: Lee Mac on March 10, 2011, 04:47:24 PM
Didn't Keith post a few Zip functions somewhere on here?

Aha! Found 'em!

http://www.theswamp.org/index.php?topic=31097.msg366864#msg366864 (http://www.theswamp.org/index.php?topic=31097.msg366864#msg366864)
Title: Re: Unzip a file programmatically?
Post by: kenkrupa on March 10, 2011, 05:32:11 PM
I just shared a specific folder in Program Files (Win 7 x64) and unzipped to it. Does that help ?

I can't make the folder shared on the user's system. But I think I have thought my way out of this. Here's the long story:

I offer a KCS Productivity Pack that gets installed in my folder (Kcs_Acad or Kcs_AEC) under Program Files, using Innosetup, and have done it that way for years. In the near future, I expect another party to provide my program to users but install it their own way in their own location (not under program files). So here I am looking to do it both ways, and be able to provide updates to both kinds of installations. Previously, I would just have the user download an updated installation file. That will still work for my existing customers, but not for those who will have it installed in the alternate location. Hence, I thought if I could download an update zip file, I could extract the files to whichever of those locations (my program knows where it is installed).

What I have come up with for a solution now is this: if my program path matches "*Program Files*", and is not on XP, I will connect them to download an updated installation file and let them run it, just as previously. If it's in the alternate location, I will download the update zip and extract the files to where I know they should go automatically. To overcome the "Replace" issue, I can add to your code to delete the existing file before extracting it.

Whew - I think that should do it. Thanks for your help.
Title: Re: Unzip a file programmatically?
Post by: kenkrupa on March 10, 2011, 08:12:56 PM
One last issue: when extracting files with this code, each file gets the current time rather than its time in the zip file. Keeping the original time stamp would be preferable. Any way to make this happen?