TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: dgpuertas on October 15, 2023, 02:29:42 PM

Title: create zip windows 11
Post by: dgpuertas on October 15, 2023, 02:29:42 PM

I need to create a zip file for any files no create only one file.

I used (setq fso (vlax-create-object "Scripting.FileSystemObject")) to doit

But in windows 11 is not running. (i thinks so)

I try to use PowerShell with this command

(startapp "powershell.exe" (strcat "-Command Compress-Archive -path " filename " -Update -DestinationPath "fileZIP " -CompressionLevel Fastest"))

But in any computers does not run. I think that is the Execution police is restricted
But command Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope CurrentUser

I try to create a ps1 file whit instructions but PowerShell said

No se puede cargar el archivo ps1 porque la ejecuci󮠤e scripts está deshabilitada en este sistema. Para obtener más informaci󮬠consulta el tema
about_Execution_Policies en https:/go.microsoft.com/fwlink/?LinkID=135170.
    + CategoryInfo          : SecurityError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : UnauthorizedAccess



Anyone knows a simple version to create zip file.
The command must be executed in three party computer.  I wouldn't like to force you to install 7zip or any other software

Title: Re: create zip windows 11
Post by: BIGAL on October 15, 2023, 07:45:30 PM
This is unzip to a directory, note the single quote  ' '" may be what you want.

Code: [Select]
(vl-mkdir "c:\\CAD-TOOLS")

(setq filename (getfiled "Select the File \"Cad tools 12-09-2023\"" "" "ZIP" 16))

; unzip
(startapp (strcat "powershell -command Expand-Archive -Path '" filename "' -DestinationPath 'C:/CAD-TOOLS' -FORCE"))
(alert "programs unzipped to C:/VFT-CAD-TOOLS")
Title: Re: create zip windows 11
Post by: dgpuertas on October 16, 2023, 06:48:32 AM
Thanks Bigal,

Its de opposite task, varius files convert into a one zip (and delete the files)
PowerShell i dont know if it works because the Execution police is restricted


Title: Re: create zip windows 11
Post by: kozmos on October 16, 2023, 10:26:43 AM

I need to create a zip file for any files no create only one file.

I used (setq fso (vlax-create-object "Scripting.FileSystemObject")) to doit

But in windows 11 is not running. (i thinks so)

I try to use PowerShell with this command

(startapp "powershell.exe" (strcat "-Command Compress-Archive -path " filename " -Update -DestinationPath "fileZIP " -CompressionLevel Fastest"))

But in any computers does not run. I think that is the Execution police is restricted
But command Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope CurrentUser

I try to create a ps1 file whit instructions but PowerShell said

No se puede cargar el archivo ps1 porque la ejecuci󮠤e scripts está deshabilitada en este sistema. Para obtener más informaci󮬠consulta el tema
about_Execution_Policies en https:/go.microsoft.com/fwlink/?LinkID=135170.
    + CategoryInfo          : SecurityError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : UnauthorizedAccess



Anyone knows a simple version to create zip file.
The command must be executed in three party computer.  I wouldn't like to force you to install 7zip or any other software

My code using Shell.application is still working under Windows 11, maybe you can give it a try.
Code - Auto/Visual Lisp: [Select]
  1. (Defun vldcl-EmptyZIP (fnn / VAL)  
  2.   (and (or fnn (setq fnn (strcat (vl-filename-mktemp) ".zip")))
  3.        (setq val (open fnn "w"))
  4.        (progn
  5.          (foreach abc '(80 75 5 6) (write-char abc val))
  6.          (repeat 18 (write-char 256 val))
  7.          (close val)
  8.        )
  9.   )
  10.   (findfile fnn)
  11. )
  12. ;;; SRC CAN BE FOLDER/FILE OR FOLDERLIST/FILELIST OR MIXED
  13. (Defun vldcl-AddToZIP (src fnn / VLO ZIP)
  14.   (and (= (type src) 'str) (setq src (list src)))
  15.   (and (or (findfile fnn) (setq fnn (vldcl-EmptyZIP fnn)))
  16.        (setq vlo (vlax-create-object "Shell.Application")
  17.              zip (vlax-invoke vlo "NameSpace" fnn)
  18.        )
  19.        (progn
  20.          (foreach abc src
  21.            (and (setq abc (cond ((vl-file-directory-p abc)
  22.                                  (vlax-invoke vlo "NameSpace" abc)
  23.                                 )
  24.                                 ((findfile abc))
  25.                           )
  26.                 )
  27.                 (vlax-invoke zip "CopyHere" abc)
  28.            )
  29.          )
  30.          (vlax-release-object zip)
  31.          (vlax-release-object vlo)
  32.        )
  33.   )
  34.   (findfile fnn)
  35. )
  36.  

Unzip code can be found @ http://www.theswamp.org/index.php?topic=58631.0
Title: Re: create zip windows 11
Post by: dgpuertas on October 17, 2023, 08:22:38 AM
Thanks a lot,

Ill try.
Title: Re: create zip windows 11
Post by: BIGAL on October 17, 2023, 08:26:51 PM
My $0.05 2 lines note the use of single quote as stated earlier.

Code: [Select]
(setq filename "D:/acadtemp/*.lsp" filezip "D:/acadtemp/lispzip.zip")
(startapp (strcat "powershell -Command Compress-Archive -path '" filename "' -Update -DestinationPath '" fileZIP "' -CompressionLevel Fastest"))
Title: Re: create zip windows 11
Post by: dgpuertas on October 18, 2023, 12:38:02 PM
Thaks Bigal

Another question
if I need to zip diferent files how do it?
Example:
File1.ddy  file1.da1   file1.par
All in the same Folder.

into file1.zip
and rename to
File1.mex

Thanks again


Title: Re: create zip windows 11
Post by: kozmos on October 18, 2023, 11:07:36 PM
Thaks Bigal

Another question
if I need to zip diferent files how do it?
Example:
File1.ddy  file1.da1   file1.par
All in the same Folder.

into file1.zip
and rename to
File1.mex

Thanks again

Very easy task using my code, just one line.
If the files are in "d:\\dir":
(vldcl-AddToZIP (list "d:\\dir\\File1.ddy" "d:\\dir\\file1.da1" "d:\\dir\\file1.par") "d:\\File1.zip")

If  "d:\\dir" only has these files and you want to zip the folder:
(vldcl-AddToZIP "d:\\dir"  "d:\\File1.zip")

If the files/folder are big, you may need to wait for a few seconds before renaming the zip file.
Title: Re: create zip windows 11
Post by: dgpuertas on October 19, 2023, 09:54:36 AM
Hi Kosmos,

Thanks a lot. For me vldcl-AddToZIP works fine.

But other colegues said that it not work in their computers, and i dont know why.

For this reason i want to try other method by PowerShell.

Thanks again Kosmos, for me is useful
Title: Re: create zip windows 11
Post by: 57gmc on October 19, 2023, 10:20:35 AM
But other colegues said that it not work in their computers, and i dont know why.
Have you added the vldcl-AssToZip function to the other pc's?
Title: Re: create zip windows 11
Post by: dgpuertas on October 23, 2023, 10:25:37 AM
Hi kosmos,

yes, i create a .fas file with all funcions.
Create a empty zip file but i dont know why.

In my computer works fine.




Title: Re: create zip windows 11
Post by: kozmos on October 23, 2023, 10:58:34 AM
Hi kosmos,

yes, i create a .fas file with all funcions.
Create a empty zip file but i dont know why.

In my computer works fine.
It seemed the empty ZIP is created. If you can directly drag files into the empty ZIP file, the program should also be able to do it. However, I will suggest you to test the source code on the not-working PC to find out which line of code failed.
Title: Re: create zip windows 11
Post by: BIGAL on October 23, 2023, 08:10:05 PM
Had another go with 2 files. Hope this makes sense.

Code: [Select]
(setq filename (strcat (chr 39) "D:/acadtemp/test.lsp" (chr 39) ", " (chr 39) "D:/acadtemp/mypdfs.scr" (chr 39)) filezip "D:/acadtemp/lispzip.zip")
(setq fo (open (setq fname "D:\\acadtemp\\alan.bat") "w"))
(write-line (strcat "powershell -Command Compress-Archive -path " filename " -Update -DestinationPath '" fileZIP "' -CompressionLevel Fastest") fo)
(close fo)
(startapp "D:\\acadtemp\\alan.bat")