PhoeniX
(Fresh Scripter)
2003-06-13 04:33 AM
Recursive Zip

How can I make sure this script does not use text from the file name as an option in the zip string?

:create_zip
$cmd=" wzzip -a -ex -rp "
$cmd=$cmd+' "$basedir\'+LTRIM(RTRIM($filename))+'.zip" "$basedir\'+LTRIM(RTRIM($filename))+'" '
SHELL '%comspec% /c $cmd '

Thanks Heaps
Phoe


NTDOCAdministrator
(KiX Master)
2003-06-13 05:34 AM
Re: Recursive Zip

Phoenix,

Can you please explain in a little more detail what it is your trying to backup.

Files? Folders? You use $filename but you don't list/show it in code as to what it is defined as.

Here is an example of using the program. Just not sure what you mean or really want.

You DON'T want the completed zip file to contain any part of the file zipped? What do you want it named?

OR is it that the command is not working at all?

If so, maybe this code snipet will help.


$Files='"C:\My Documents\*.*"'
$Backup='C:\PROGRA~1\WinZip\WZZIP.EXE -ee -o -r -P "D:\Backup\backup.zip" $Files'
shell $Backup


[ 13. June 2003, 06:06: Message edited by: NTDOC ]


PhoeniX
(Fresh Scripter)
2003-06-13 07:08 AM
Re: Recursive Zip

NTDOC,

it goes as follows:

break on
;
$basedir="c:\cli\Clients"
$filename=dir("$basedir\*")
$archdir="c:\zip\"

WHILE ($filename <> "") AND (@error = 0)
IF ($filename <> ".") AND ($filename <> "..") AND (GetFileAttr($basedir+"\"+$filename) & 16)
GOSUB "create_zip"
ENDIF
$filename=dir()
LOOP
EXIT

:create_zip
$cmd=" wzzip -a -ex -rp "
$cmd=$cmd+' "$basedir\'+LTRIM(RTRIM($filename))+'.zip" "$basedir\'+LTRIM(RTRIM($filename))+'" '
SHELL '%comspec% /c $cmd '

It captures the root of each directory and archives everything below with the title of the root directory.zip

When it archives, it finds -v in some directory names - wzzip thinks this is an option.

Phoe.


NTDOCAdministrator
(KiX Master)
2003-06-13 11:00 AM
Re: Recursive Zip

Phoenix,

Please give this code a try. Make sure WZZIP.EXE is in your path, or use the full path as in my example.

NOTE:

-o = Change the Zip file's file date to the same as the newest file in the Zip file
-ee = extra (enhanced deflate - smallest file)
-r = Recurse into subfolders (include subfolders). This option requires the -p or -P option.
-p|P= Store folder names. A lower case p stores only the names of folders recursed
(subfolders included) via the -r option, while an upper case P stores all folder
information specified on the command line

Example: wzzip.exe -rp Would only contain the child folder names
wzzip.exe -rP Would contain the FULL path and child folder names



break on
$basedir="c:\cli\Clients"
$filename=dir("$basedir\*")
$archdir="c:\zip\"
WHILE ($filename <> "") AND (@error = 0)
IF ($filename <> ".") AND ($filename <> "..") AND (GetFileAttr($basedir+"\"+$filename) & 16)
shell 'C:\PROGRA~1\WinZip\WZZIP.EXE -eeorP $archdir$filename.zip $basedir\$filename\*.*'
ENDIF
$filename=dir()
LOOP
EXIT 1


NTDOCAdministrator
(KiX Master)
2003-06-13 11:20 AM
Re: Recursive Zip

WinZip beta 9
http://www.winzip.com/betawz.cgi
http://download.winzip.com/cgi-bin/auth/wzbeta90.exe?xfermode=80320448&srcip=24.205.6.96&From=&file=wzbeta90.exe

What's new in beta 9
http://www.winzip.com/whatsnew90.htm

WinZip Command Line Support Add-On 1.1 Beta
Requires WinZip beta 9
http://www.winzip.com/wzclineb.cgi
http://download.winzip.com/cgi-bin/auth/wzbetacl.exe?xfermode=58590595&srcip=24.205.6.96&From=&file=wzbetacl.exe


NTDOCAdministrator
(KiX Master)
2003-06-13 06:18 PM
Re: Recursive Zip

I guess the Phoenix has flown south for the Winter. Perhaps will return Monday [Roll Eyes]

LonkeroAdministrator
(KiX Master Guru)
2003-06-13 06:57 PM
Re: Recursive Zip

doc, dude...
postprepping quotes? [Confused]
you should remember that your quotes most-likely never have correct syntax like we see above...


NTDOCAdministrator
(KiX Master)
2003-06-13 07:50 PM
Re: Recursive Zip

Yeah, I know, you're right. I manually massaged it to work. Hey, what can I say dude... I love your program too much and try to use it for unintended purposes. [Big Grin]

LonkeroAdministrator
(KiX Master Guru)
2003-06-14 04:04 AM
Re: Recursive Zip

I could make it work for that purpose too [Big Grin]
if you would just ask me to! [Wink]


NTDOCAdministrator
(KiX Master)
2003-06-14 09:26 AM
Re: Recursive Zip

Hey that would be great Lonkero.

Would you make it work for that purpose too? PLEASE!!!


PhoeniX
(Fresh Scripter)
2003-06-16 05:32 AM
Re: Recursive Zip

NTDOC,

I think I've found the problem. Its not the way that the variables are passed to shell. Its wzzip, I just did a cmd line test of it and it failed showing that you can not have -v combined with other options.

wzzip -a -ex -rp "c:\files\thisdir.zip" "c:\files\exdir -v exdir\*.*"

Well now I have to find another way around. Maybe a rename script.

Thanks for your help

Phoe


NTDOCAdministrator
(KiX Master)
2003-06-16 09:36 AM
Re: Recursive Zip

Phoenix,

I'm not having any problem creating the zip file on the command line.
Here is what I have.

KIXTART 4.21
Windows 2000 SP3
IE 6.01
Winzip 9.0 beta
Winzip Command-line add-on 1.1 (for Winzip 9 beta)

Here is the full commandline used in a DOS Window:
(I don't have WZZIP.EXE in path so I use full path)

C:\PROGRA~1\WinZip\WZZIP.EXE -a -ex -rp "c:\files\thisdir.zip" "c:\files\exdir -v exdir\*.*"

Here is the listing of the files and directories I have.

quote:
C:\FILES\- V -ex -v
C:\FILES\- V -ex -v\egensock.cpp
C:\FILES\- V -ex -v\fgensock.cpp
C:\FILES\- V -ex -v\ggensock.cpp
C:\FILES\-v
C:\FILES\-v\Rebel
C:\FILES\-v\Rebel\Contents.txt
C:\FILES\-v\Rebel\Readme.txt
C:\FILES\-v\Rebel\Temp - V -v
C:\FILES\-v\Rebel\Temp - V -v\NSDSESS.TXT
C:\FILES\-v\moose.jpg
C:\FILES\Clients
C:\FILES\Clients\files.txt
C:\FILES\Compaq
C:\FILES\Compaq\NextGen
C:\FILES\Compaq\NextGen\IBM
C:\FILES\Compaq\NextGen\IBM\- v - ex -r -p -P -ee
C:\FILES\Compaq\NextGen\IBM\- v - ex -r -p -P -ee\-v
C:\FILES\Compaq\NextGen\IBM\- v - ex -r -p -P -ee\Copy of -v
C:\FILES\Compaq\NextGen\IBM\- v - ex -r -p -P -ee\Copy of sdk45y.txt
C:\FILES\Compaq\NextGen\IBM\- v - ex -r -p -P -ee\sdk45y.txt
C:\FILES\Compaq\NextGen\IBM\Bakegensock.cpp
C:\FILES\Compaq\NextGen\IBM\Bakfgensock.cpp
C:\FILES\Compaq\NextGen\IBM\Bakggensock.cpp
C:\FILES\Compaq\NextGen\egensock.cpp
C:\FILES\Compaq\NextGen\fgensock.cpp
C:\FILES\Compaq\NextGen\ggensock.cpp
C:\FILES\Compaq\fort.txt
C:\FILES\GENSOCK
C:\FILES\GENSOCK\gensock.cpp
C:\FILES\GENSOCK\gensock.h
C:\FILES\HP
C:\FILES\HP\-ex
C:\FILES\HP\-ex\snsock.cp
C:\FILES\HP\Copy of leftck.cpp
C:\FILES\HP\leftck.cpp
C:\FILES\Testing -v
C:\FILES\Testing -v\egensock.cpp
C:\FILES\Testing -v\fgensock.cpp
C:\FILES\Testing -v\ggensock.cpp
C:\FILES\exdir -v exdir
C:\FILES\exdir -v exdir\egensock.cpp
C:\FILES\exdir -v exdir\fgensock.cpp
C:\FILES\exdir -v exdir\ggensock.cpp
C:\FILES\files.txt

It created a single zip file with all folders.

I use the -ee switch because is creates a smaller file then -ex
that was the old highest compression switch, now it is -ee
I also use -rP (Capital P) to get the full path of directories in
the zip file as well.

I then modified the KiXtart file to use the new path
(not the same path you listed before) and re-ran the code.

I got the same error. That is because the quotes were not sufficient
to capture all of the information.

I modified the command line to this: (you don't need a space and - switch for each option
it can be supplied with a single - followed by multiple options.
shell 'C:\PROGRA~1\WinZip\WZZIP.EXE -eeorP "$archdir$filename.zip" "$basedir\$filename\*.*"'

This now produces the following files in the C:\ZIP folder:
- V -ex -v.zip
Clients.zip
Compaq.zip
exdir -v exdir.zip
GENSOCK.zip
HP.zip
Testing -v.zip
-v.zip

Each zip file contains all the files within its own folder and includes the FULL path.

Please retry the code EXACTLY as I've supplied and you should find it now zips up the files as expected.


break on
$basedir="c:\files"
$filename=dir("$basedir\*")
$archdir="c:\zip\"
WHILE ($filename <> "") AND (@error = 0)
IF ($filename <> ".") AND ($filename <> "..") AND (GetFileAttr($basedir+"\"+$filename) & 16)
shell 'C:\PROGRA~1\WinZip\WZZIP.EXE -eeorP "$archdir$filename.zip" "$basedir\$filename\*.*"'
ENDIF
$filename=dir()
LOOP
EXIT 0


NTDOCAdministrator
(KiX Master)
2003-06-17 09:32 AM
Re: Recursive Zip

Phoenix,

Did you get a chance to run this?


NTDOCAdministrator
(KiX Master)
2003-06-21 04:04 AM
Re: Recursive Zip

Phoenix - WHAT'S UP

Another flash in the pan? Come on back, the waters fine.

Why do we get so many people come by and ask a question, then they either don't check the answer or they get the answer and never come back?

KiXtart.org is a GREAT place with a lot of good people. Rod was saying that something like 17,000 people have downloaded Shawn's KiXforms DLL. That is a lot of people, a rather large SILENT Majority so it would seem.


PhoeniX
(Fresh Scripter)
2003-06-25 06:47 AM
Re: Recursive Zip

NTDOC,

yeah I'm still here working on this. I just haven't been able to get back to it over the last week.

You said your script created a single zip file?
"It created a single zip file with all folders. "

I've just installed winzip9 +cmdline and I'll get back into it now.

Thanks for your help
Phoe.


PhoeniX
(Fresh Scripter)
2003-06-25 07:39 AM
Re: Recursive Zip

NTDOC,

Tested the script with winzip 8 +cmdline and wzzip switches

Tested the script with winzip 9 beta +cmdline and
wzzip switches

Winzip 8 reads the line and if it sees -v or - v in the string passed to the command line it will fail.

ERROR: option -v, -vi cannot be combined with option -a, -d, -f, -i, -u
Program is terminating!

Winzip 9 does not have this problem.

Perhaps I should test other products for the archive job too.


NTDOCAdministrator
(KiX Master)
2003-06-25 10:39 AM
Re: Recursive Zip

Phoenix,

What OS are you using? I tested this on both Windows 95 and 2000 using WinZip v8.0 originally.

Then I upgraded to WinZip 9 beta and it still worked fine.

Check your path to make sure you don't have an OLD version of the command line tools somewhere.

Also copy the code exactly as above. I have run it many times and I do not get that error anymore.

The error was caused by a misuse of quotes "" for the %comspec% call. With the correct usage it works just fine.

It creates a zip file for every top folder under the target folder with recursive files in each zip for each folder.


PhoeniX
(Fresh Scripter)
2003-06-27 01:31 AM
Re: Recursive Zip

NTDOC,

I ran your code posted: posted 16. June 2003 09:36.

It functions with winzip9 beta - cmd line
but in winzip8 cmd line, it will fail on file names with -v in them.
(0004642 Rider-Bell Denise Marilyn -v Carison)

This is the code I ran, with the change for the winzip8 cmd line.
--------------
break on
$basedir="c:\files"
$filename=dir("$basedir\*")
$archdir="c:\zip\"
WHILE ($filename <> "") AND (@error = 0)
IF ($filename <> ".") AND ($filename <> "..") AND (GetFileAttr($basedir+"\"+$filename) & 16)
shell 'C:\PROGRA~1\WinZip\WZZIP.EXE -a -ex -rp "$archdir$filename.zip" "$basedir\$filename\*.*"'
ENDIF
$filename=dir()
LOOP
EXIT 0
------------

Tested on a WindowsXP WZ8+cmdline

I hope I can see it your way, then it may work.
Thanks for your patience
Phoe.


NTDOCAdministrator
(KiX Master)
2003-06-27 10:40 AM
Re: Recursive Zip

Okay Phoenix...

It was a pain in the butt, but I un-installed WinZip 9 and rebooted. Then I re-installed all Winzip 8.0 and command-line add-on v1.0

I can confirm that 8.0 DOES NOT work. Version 9.0 beta DOES WORK fine.

Not sure what you're really trying to do here though. There are plenty of applications and methods for backing up files or systems.

Using Winzip for this purpose is okay for a quicky, but not very robust. Why do you need separate zip files for each folder?

Why not upgrade to Winzip 9 beta? It is a free upgrade for registered users.

Maybe if you give us more details on what the FULL STORY is for the archiving purposes we can either script something better or recommend a better product.

In the same/similar category as Winzip, there is WinRaR too.


LonkeroAdministrator
(KiX Master Guru)
2003-06-27 11:02 AM
Re: Recursive Zip

if you want to compress the files (no need for that either) during the process, you could use windows cab-files and the udf that creates them.

they are browseable and extractable via windows explorer or extract.exe (part of windows) or winrar (or any other good packaging util)


masken
(MM club member)
2003-06-27 11:06 AM
Re: Recursive Zip

Someone slap me for suggesting WinRAR [Wink]

...or rather, the 32bit commandline version rar.exe included with WinRAR.

[ 27. June 2003, 11:11: Message edited by: masken ]


Sealeopard
(KiX Master)
2003-06-27 06:55 PM
Re: Recursive Zip

Or even NTBACKUP (comes free with Windows [Big Grin] ). You can even create your own backup jobs with KiXtart as the backup job files are plain-text files, than call NTBACKUP via command-line and there you go.

LonkeroAdministrator
(KiX Master Guru)
2003-06-28 12:50 AM
Re: Recursive Zip

ntbackup is fantastic (use it currently for my most important data-backups) but it needs to access desktop...
and it's totally interrubtable by user currently logged on...
at least on NT [Wink]


Sealeopard
(KiX Master)
2003-06-28 04:15 AM
Re: Recursive Zip

Have you tried to run it via Task Scheduler under it's own account? Then the current user should not be able to see the GUI.

NTDOCAdministrator
(KiX Master)
2003-06-30 08:54 AM
Re: Recursive Zip

NTBACKUP would not allow you to accomplish one of the requirements of creating a separate archive for each parent folder.
(well, one could I guess, but not very efficiently)

Calling Phoenix...!! What is your input to this? What is the reason and FULL requirements?

Plenty of knowledgeable people here willing to help you, but we need all the details.

[ 30. June 2003, 08:56: Message edited by: NTDOC ]


Sealeopard
(KiX Master)
2003-06-30 03:23 PM
Re: Recursive Zip

Yes, it can do that. Create a script that calls NTBACKUP multiple times, and each time one of the parent folder will get backed up. Just rewrite the NTBACKUP backup set file to point to each of the parent folder.

NTDOCAdministrator
(KiX Master)
2003-06-30 06:56 PM
Re: Recursive Zip

Yeah, that is why I said not very efficient though at least time wise.

Hopefully Phoenix will reply with his real requirements.


Fernando Madruga
(Starting to like KiXtart)
2003-07-08 01:01 PM
Re: Recursive Zip

Using 4NT and Info-ZIP:

for /a:D/H %f in ( * ) ( echo %f %+ zip -9 -r -! -D "%f.zip" "%f\*" )

This will create one zip file for each folder in the current one with the same name as the folder using max compression (-9), recursion (-r), NT file attributes (-!), and not storing the "folder" entries (-D).

I know this isn't Kix, but NTDOC and others will gladly "KiX" it... [Smile]

The advantage of this Zip is that it is free...


LonkeroAdministrator
(KiX Master Guru)
2003-07-08 01:10 PM
Re: Recursive Zip

eh.
you need the udf:
MakeCab() - Create windows cabinet file package with specified files included

to use this.
code:
$full_paths_to_Files ="list of files which you generate"
$packagefile = "the_package-file's fullpath"

$returncode=makecab($packagefile,$full_paths_to_Files)
if @error or len($returncode)
"error occured:" $returncode+@error
else
"package created"
endif



NTDOCAdministrator
(KiX Master)
2004-04-22 12:15 AM
Re: Recursive Zip

Correct path to this UDF now that the board has been upgraded.

MakeCab() - Create windows cabinet file package with specified files included



NTDOCAdministrator
(KiX Master)
2006-12-05 07:21 AM
Re: Recursive Zip

Quote:
Correct path to this UDF now that the board has been upgraded.

MakeCab() - Create windows cabinet file package with specified files included



And this upgrade didn't break it this time

.


Björn
(Korg Regular)
2006-12-20 11:14 AM
Re: Recursive Zip

Also check the syntax. compare these two:
Code:
break on
;
$basedir="c:\cli\Clients"
$filename=dir("$basedir\*")
$archdir="c:\zip\"

WHILE ($filename <> "") AND (@error = 0)
IF ($filename <> ".") AND ($filename <> "..") AND (GetFileAttr($basedir+"\"+$filename) & 16)
GOSUB "create_zip"
ENDIF
$filename=dir()
LOOP
EXIT

:create_zip
$cmd=" wzzip -a -ex -rp "
$cmd=$cmd+' "$basedir\'+LTRIM(RTRIM($filename))+'.zip" "$basedir\'+LTRIM(RTRIM($filename))+'" '
SHELL '%comspec% /c $cmd '

Syntax-corrected:
Code:
break on
;
$basedir="c:\cli\Clients"
$filename=dir("$basedir\*")
$archdir="c:\zip\"

WHILE $filename <> "" AND @error = 0
IF $filename <> "." AND $filename <> ".." AND GetFileAttr($basedir+"\"+$filename) & 16
GOSUB "create_zip"
ENDIF
$filename=dir()
LOOP
EXIT

:create_zip
$cmd=" wzzip -a -ex -rp "
$cmd=$cmd+' "$basedir\'+LTRIM(RTRIM($filename))+'.zip" "$basedir\'+LTRIM(RTRIM($filename))+'" '
SHELL '%comspec% /c $cmd '



Sidenote: gosub and etc is.. dangerous. I started out with using that as well, but there's better options.


LonkeroAdministrator
(KiX Master Guru)
2006-12-20 02:54 PM
Re: Recursive Zip

björn, you just removed the brackets?
as I can't find any real syntax difference...


Björn
(Korg Regular)
2006-12-20 03:39 PM
Re: Recursive Zip

Aye, that I did. something tells me that that works as well. haven't seen it before tho.

Les
(KiX Master)
2006-12-20 03:44 PM
Re: Recursive Zip

There is lonkifying and then there is deMCAing. That is classic deMCAing.

Howard Bullock
(KiX Supporter)
2006-12-22 03:01 AM
Re: Recursive Zip

http://home.comcast.net/~habullock/habobjects.htm

Just use one of the DIR functions to get an array of filenames. Then:
Code:
?
$Zip2 = $HABObject.Zip()

$files = "C:\Data\Scripts\PerlCtrl\objects\Zip.html",
         "C:\Data\Scripts\PerlCtrl\objects\HABobjects2.DLL",
         "C:\data\scripts\[censored].kix"

for each $file in $files
    $member = $Zip2.addFile( $file )
    if $Zip2.writeToFileNamed( "C:\Data\Scripts\PerlCtrl\objects\Test.zip" ) = 0
       ? "Added: " + $file
    endif
next
 


NTDOCAdministrator
(KiX Master)
2006-12-22 03:31 AM
Re: Recursive Zip

What nasty stuff you writing that the board censors it Howard?


"C:\data\scripts\[censored].kix" ?