Author Topic: 7zip via lisp  (Read 1234 times)

0 Members and 2 Guests are viewing this topic.

domenicomaria

  • Swamp Rat
  • Posts: 743
7zip via lisp
« on: June 19, 2024, 04:08:16 AM »
since I need to save a copy of two folders every day
by compressing them into a 7zip file,
I would like to automate this procedure with lisp

Is there anyone who can give me some suggestions?

Thank you

dexus

  • Bull Frog
  • Posts: 230
Re: 7zip via lisp
« Reply #1 on: June 19, 2024, 04:31:00 AM »
It's not 7zip, but if a regular zip file would work as well you can start here: https://www.theswamp.org/index.php?topic=58636.msg616688;topicseen#msg616688

VovKa

  • Water Moccasin
  • Posts: 1636
  • Ukraine
Re: 7zip via lisp
« Reply #2 on: June 19, 2024, 04:55:28 AM »
Code: [Select]
(startapp "full path to 7z.exe" "a \"D:\\dest file 1.7z\" \"D:\\src folder\"")

JohnK

  • Administrator
  • Seagull
  • Posts: 10674
Re: 7zip via lisp
« Reply #3 on: June 19, 2024, 10:01:50 AM »
I had one a while back I made to demonstrate.
https://www.theswamp.org/index.php?topic=14793.msg178860#msg178860
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

BIGAL

  • Swamp Rat
  • Posts: 1459
  • 40 + years of using Autocad
Re: 7zip via lisp
« Reply #4 on: June 19, 2024, 08:26:39 PM »
This is opposite an unzip using powershell.

Code: [Select]
(startapp (strcat "powershell -command Expand-Archive -Path '" filename "' -DestinationPath 'C:/CAD-TOOLS' -FORCE"))
Pretty sure should be a ZIP syntax. https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.archive/compress-archive?view=powershell-7.4
A man who never made a mistake never made anything

domenicomaria

  • Swamp Rat
  • Posts: 743
Re: 7zip via lisp
« Reply #5 on: June 20, 2024, 02:57:08 AM »
thanks everyone...
... I have to do my own tests...

domenicomaria

  • Swamp Rat
  • Posts: 743
Re: 7zip via lisp
« Reply #6 on: June 20, 2024, 04:01:13 AM »
Code: [Select]
(startapp "full path to 7z.exe" "a \"D:\\dest file 1.7z\" \"D:\\src folder\"")

I need to compress 2 folders in 1 7zip file

So I need, first of all, to compress the first folder into a destination file (7z)
and then repeat the same thing for the second folder,
always adding it to the same destination file

but STARTAPP DOES NOT WAIT for the first process to finish.


So the second process begins without waiting the end of the first one.

And then something goes wrong and the result is that
the second folder is not added to the destination file

with dos_exewait, however, it works

I should know what the syntax is for the 7zip command
to add multiple folders (a list of folders) all in the same destination file
and this only with 1 command

Code - Auto/Visual Lisp: [Select]
  1. (defun c:7Z ( / cdate dd dst-ffn mm src-fldr-1 src-fldr-2 yy)
  2.    (setq cdate (rtos (getvar "cdate") 2 0) )
  3.    (setq yy (substr cdate 3 2)
  4.          mm (substr cdate 5 2)
  5.          dd (substr cdate 7 2)
  6.    )
  7.    (setq cdate (strcat dd mm yy) )
  8.  
  9.    
  10.    (setq dst-ffn  (strcat "G:\\@\\VLISP22-DDI-" cdate ".7Z")
  11.          src-fldr-1 "G:\\@\\VLISP22\\"
  12.          src-fldr-2 "G:\\@\\DDI\\"
  13.    )
  14.    (if (findfile dst-ffn) (vl-file-delete dst-ffn) )
  15.    
  16.    (dos_exewait (strcat "C:\\Program Files\\7-Zip\\7Z.exe" " a "dst-ffn " " src-fldr-1) )
  17.    
  18.    (dos_exewait (strcat "C:\\Program Files\\7-Zip\\7Z.exe" " a "dst-ffn " " src-fldr-2) )
  19.    
  20. )
  21.  
« Last Edit: June 20, 2024, 04:06:58 AM by domenicomaria »

VovKa

  • Water Moccasin
  • Posts: 1636
  • Ukraine
Re: 7zip via lisp
« Reply #7 on: June 20, 2024, 07:43:31 AM »
Code: [Select]
(startapp "full path to 7z.exe" "a \"D:\\dest file 1.7z\" \"D:\\src folder\"")

I need to compress 2 folders in 1 7zip file
(startapp "full path to 7z.exe" "a \"D:\\dest file.7z\" \"D:\\src folder 1\" \"D:\\src folder 2\"")

domenicomaria

  • Swamp Rat
  • Posts: 743
Re: 7zip via lisp
« Reply #8 on: June 20, 2024, 01:12:20 PM »
(startapp "full path to 7z.exe" "a \"D:\\dest file.7z\" \"D:\\src folder 1\" \"D:\\src folder 2\"")

Thank you VovKa.
It works well.

however it would be interesting to find a way to emulate dos_exewait...
... but this is another matter ...

domenicomaria

  • Swamp Rat
  • Posts: 743
Re: 7zip via lisp
« Reply #9 on: June 20, 2024, 01:41:21 PM »
however it would be interesting to find a way to emulate dos_exewait...
... but this is another matter ...

I say this, because after compressing 2 folders into 1 7zip file,
I need to copy this file to another hard disk...
... and vl-file-copy doesn't wait for the process started by startapp to finish...
...and so I still use dos_exewait !

PKENEWELL

  • Bull Frog
  • Posts: 324
"When you are asked if you can do a job, tell 'em, 'Certainly I can!' Then get busy and find out how to do it." - Theodore Roosevelt

ribarm

  • Gator
  • Posts: 3327
  • Marko Ribar, architect
Re: 7zip via lisp
« Reply #11 on: June 21, 2024, 10:37:34 AM »
I think that you don't need to use : dos_exewait...
Maybe this is what you are after :
Code: [Select]
(while (not (findfile fullpath+filename+ext))
)
(vl-file-copy fullpath+filename+ext dest-fullpath+filename+ext)

HTH.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

domenicomaria

  • Swamp Rat
  • Posts: 743
Re: 7zip via lisp
« Reply #12 on: June 22, 2024, 12:28:28 AM »
I think that you don't need to use : dos_exewait...
Maybe this is what you are after :
Code: [Select]
(while (not (findfile fullpath+filename+ext))
)
(vl-file-copy fullpath+filename+ext dest-fullpath+filename+ext)

HTH.

it's an idea !