Author Topic: Unzip a file programmatically?  (Read 3571 times)

0 Members and 1 Guest are viewing this topic.

kenkrupa

  • Newt
  • Posts: 73
Unzip a file programmatically?
« on: March 09, 2011, 08:43:01 PM »
Any way to unzip a file programmatically (from AutoCAD, using LISP)?

CAB

  • Global Moderator
  • Seagull
  • Posts: 10311
Re: Unzip a file programmatically?
« Reply #1 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!
« Last Edit: March 09, 2011, 10:41:15 PM by CAB »
I've reached the age where the happy hour is a nap. ()
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11653
  • class keyThumper<T>:ILazy<T>
Re: Unzip a file programmatically?
« Reply #2 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."))
« Last Edit: March 10, 2011, 12:58:42 AM by Kerry »
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

Mark

  • Custom Title
  • Administrator
  • Seagull
  • Posts: 28545
Re: Unzip a file programmatically?
« Reply #3 on: March 10, 2011, 08:50:22 AM »
Have a play with something like this.
Sweet!
TheSwamp.org  (serving the CAD community since 2003)

kenkrupa

  • Newt
  • Posts: 73
Re: Unzip a file programmatically?
« Reply #4 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)
« Last Edit: March 10, 2011, 09:50:18 AM by kenkrupa »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11653
  • class keyThumper<T>:ILazy<T>
Re: Unzip a file programmatically?
« Reply #5 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.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

Matt__W

  • Seagull
  • Posts: 12942
  • I like my water diluted.
Re: Unzip a file programmatically?
« Reply #6 on: March 10, 2011, 03:26:13 PM »
When a file comes along, you must ZIP it...
   Now ZIP it... ZIP it good...
Autodesk Expert Elite
Autodesk Revit Architecture, Structure, MEP Mechanical and MEP Electrical Certified Professional
Building Performance Analysis Certified (BPAC v3.0)
Autodesk Navisworks 2014 Essentials

kenkrupa

  • Newt
  • Posts: 73
Re: Unzip a file programmatically?
« Reply #7 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.
« Last Edit: March 10, 2011, 04:21:59 PM by kenkrupa »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11653
  • class keyThumper<T>:ILazy<T>
Re: Unzip a file programmatically?
« Reply #8 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."))
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

Lee Mac

  • Seagull
  • Posts: 12065
  • London, England
Re: Unzip a file programmatically?
« Reply #9 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

kenkrupa

  • Newt
  • Posts: 73
Re: Unzip a file programmatically?
« Reply #10 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.

kenkrupa

  • Newt
  • Posts: 73
Re: Unzip a file programmatically?
« Reply #11 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?