Author Topic: ZIP files ZIP folders & VLISP  (Read 4122 times)

0 Members and 1 Guest are viewing this topic.

Pepe

  • Newt
  • Posts: 75
ZIP files ZIP folders & VLISP
« on: November 25, 2009, 03:14:49 AM »
I suppose it's easy in other languages, but...

How to browse inside a 'zip' file using VLISP? and...

How to deal with it as a 'folder'?...How to create it?...How to decompress it?

Thanks!

CAB

  • Global Moderator
  • Seagull
  • Posts: 10320
Re: ZIP files ZIP folders & VLISP
« Reply #1 on: November 25, 2009, 09:40:15 AM »
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.

alanjt

  • Needs a day job
  • Posts: 5323
  • Standby for witty remark...
Re: ZIP files ZIP folders & VLISP
« Reply #2 on: November 25, 2009, 11:18:08 AM »
Didn't John (Se7en) post some code for compressing/decompressing files?
Civil 3D 2017 ~ Windohz 7 64bit
Dropbox

CAB

  • Global Moderator
  • Seagull
  • Posts: 10320
Re: ZIP files ZIP folders & VLISP
« Reply #3 on: November 25, 2009, 11:37:16 AM »
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.

alanjt

  • Needs a day job
  • Posts: 5323
  • Standby for witty remark...
Re: ZIP files ZIP folders & VLISP
« Reply #4 on: November 25, 2009, 11:40:16 AM »
Civil 3D 2017 ~ Windohz 7 64bit
Dropbox

Pepe

  • Newt
  • Posts: 75
Re: ZIP files ZIP folders & VLISP
« Reply #5 on: November 25, 2009, 12:07:59 PM »
Hi!

Thank you (very, very much) to you two for answering, Alan and CAB; useful links, but it wasn't exactly what I was looking for (I must be much more precise questioning. Language matters...I'm sorry... :oops:).

Windows XP has its own compressor and I suppose it belongs to that OS and, so, it should be easy to use it via 'VLAX-CREATE-OBJECT...etc...', but I can't find which OS (ActiveX...?) object, properties and methods are able for that (...maybe...(vlax-create-object "shell.application")...?).

Does anybody know anything about this?

Thank You again

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16688
  • Superior Stupidity at its best
Re: ZIP files ZIP folders & VLISP
« Reply #6 on: November 25, 2009, 03:03:39 PM »
Here is my addition to the mix

Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

alanjt

  • Needs a day job
  • Posts: 5323
  • Standby for witty remark...
Re: ZIP files ZIP folders & VLISP
« Reply #7 on: November 25, 2009, 03:07:49 PM »
Here is my addition to the mix


Daily, automatic zipped backups to my portable drive, here I come. Very nice Keith!
Civil 3D 2017 ~ Windohz 7 64bit
Dropbox

Pepe

  • Newt
  • Posts: 75
Re: ZIP files ZIP folders & VLISP
« Reply #8 on: November 25, 2009, 03:39:12 PM »
 :-o WOW!!!

That is exactly what I was looking for !

Thank you very much (a couple of virtual beers to your health), Keith!

Lee Mac

  • Seagull
  • Posts: 12098
  • London, England
Re: ZIP files ZIP folders & VLISP
« Reply #9 on: November 25, 2009, 03:47:19 PM »
Nice Keith  :wink:

dgorsman

  • Water Moccasin
  • Posts: 2344
Re: ZIP files ZIP folders & VLISP
« Reply #10 on: November 26, 2009, 02:17:25 PM »
*yoink*   :mrgreen:

Much appreciated.  You might want to check on the leading comments: "Error hecking is limited..."   :lmao:
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

Lee Mac

  • Seagull
  • Posts: 12098
  • London, England
Re: ZIP files ZIP folders & VLISP
« Reply #11 on: November 26, 2009, 02:28:27 PM »
*yoink*   :mrgreen:

Much appreciated.  You might want to check on the leading comments: "Error hecking is limited..."   :lmao:

True... I read that as Error hacking...  but then who reads the headers these days...  :|

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16688
  • Superior Stupidity at its best
Re: ZIP files ZIP folders & VLISP
« Reply #12 on: November 26, 2009, 02:53:54 PM »
Oh no, you can't be satisfied with the code, you gotta pick apart spelling errors in the header ... :P

well, if it is that bac, then don't use it ;)

I played with it a bit last night and realized that there is a problem with the utility to zip all files in a folder to a single file IF the zip file is located in the same folder in which all files are being compressed.

example:
You have a folder C:\Stuff\Pictures\ and you want to compress all of the files in that folder to a file called C:\Stuff\Pictures\Pictures.zip When using the built in Windows compression (or any other zip utility) you generally select the files prior to the compression taking place. In this utility, the files are compressed as they are selected, this means that C:\Stuff\Pictures\Pictures.zip will be selected to be compressed into itself, clearly this will not be possible.

A fix for that situation might be as follows:

Code: [Select]
(defun AddFolder2Zip (srcFolder destFile)
  (MakeEmptyZip destFile)
  (setq app (vlax-create-object "Shell.Application"))
  (setq folder (vlax-invoke app 'NameSpace srcFolder))
  (setq destZip (vlax-invoke app 'NameSpace destFile))
  (setq files (vlax-invoke folder 'Items))
  (setq count (vlax-get-property files 'Count))
  (setq ndx 0)
  (repeat count
    (setq file (vlax-invoke files 'Item ndx))
    (if (/= (strcase (vlax-get-property file 'Name))(strcase(strcat (cadr (fnsplitl destFile))(caddr (fnsplitl destFile)))))
      (vlax-invoke destZip 'CopyHere file)
    ) 
    (setq ndx (1+ ndx))
  )
)

This will verify whether the zip file is actually being selected to be compressed and will skip it if needed.

I am adding additional error checking, and I have already determined that some systems handle the compression differently. For example, my home computer prompts you to overwrite the files in the zip file if they already exist, while my office computer will simply add the file again (thus there are 2 of the exact same files in the zip).

Determining if the file exists in the zip file should be as easy as:
Code: [Select]
(member (GetAllFilesInZip "MyFile.dwg"))

I am not sure how capitalization works in that scenario as I have not tested it.

I am glad everyone is finding it useful though.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Pepe

  • Newt
  • Posts: 75
Re: ZIP files ZIP folders & VLISP
« Reply #13 on: November 27, 2009, 06:30:45 AM »
Hi everybody!

I've been playing a while with all this stuff posted by Keith (nice work, indeed!).

A couple of questions:

First one: when zip file is just in "my documents" root path, it says "; error: <I can't transalte this part into english> : VLA-OBJECT nil"
Does anybody knows why?

Second one: zip files often contain folders and sub-folders.
Here is a little contribution to solve this. It's a simple browser of all the contents - including sub-folders - of the zip.

Code: [Select]
(defun moreinside (chkfile / cmt cnt fil its lst sbf)
  (if (= (vlax-get-property chkfile 'IsFolder) :vlax-true)
    (progn
      (setq sbf (vlax-get-property chkfile 'getfolder))
      (setq its (vlax-invoke-method sbf 'items))
      (setq cmt (vlax-get-property its 'count))
      (setq cnt 0)
      (repeat cmt
(setq fil (moreinside (vlax-invoke-method its 'item cnt)))
(setq lst (cons fil lst))
(setq cnt (1+ cnt))
)
      (vlax-release-object sbf)
      (vlax-release-object its)
      (gc)
      (cons (vla-get-name chkfile) (reverse lst))
      )
    (vla-get-name chkfile)
    )
  )
 
(defun GetAllFilesInZip (zipFile / count file filelist files folder fso ndx path)
  (setq path (car (fnsplitl zipFile)))
  (setq fso (vlax-create-object "Shell.Application"))
  (setq folder (vlax-invoke fso 'NameSpace zipFile))
  (setq files (vlax-invoke folder 'Items))
  (setq count (vlax-get-property files 'Count))
  (setq ndx 0)
  (repeat count
    (setq file (moreinside (vlax-invoke files 'Item ndx)))
    (setq filelist (append filelist (list file)))
    (setq ndx (1+ ndx))
    )
  (vlax-release-object folder)
  (vlax-release-object fso)
  (gc)
  filelist
  )

(defun showint (a b / str)
  (setq str "\n|-")
  (repeat b (setq str (strcat str "-")))
  (foreach n a
    (if (listp n)
      (progn
(princ (strcat str ">" (car n)))
(showint (cdr n) (1+ b))
)
      (princ (strcat str ">" n))
      )
    )
  )

(defun C:TESTZIPCONTENTS (/ cont filz)
  (setq filz (getfiled "Select a ZIP File" "" "zip" 8))
  (setq cont (GetAllFilesInZip filz))
  (textscr)
  (princ (strcat "\nContents of \"" (vl-filename-base filz) (vl-filename-extension filz) "\":\n|"))
  (showint cont 0)
  (princ)
  )

I've checked that "ExtractFileFromZip" function works properly for a file or folder if it is at the root of the contents of the zip file,
But, How to decompress a single file or sub-folder within a sub-folder? I've tried many ways to build the list of contents in order to do this, but without any success  :-(.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16688
  • Superior Stupidity at its best
Re: ZIP files ZIP folders & VLISP
« Reply #14 on: November 27, 2009, 10:22:40 AM »
I can successfully obtain a single folder and the files within that folder, but when there are nested folders, the method fails, even though the path is correct.

Example:
C:\MyZip.zip\SubFolder1 is returned and enumerated, however, C:\MyZip.zip\SubFolder1\Subfolder2 is not, in fact the 'NameSpace method fails here.

I'll have to investigate this more closely ...
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal