Page 2 of 2 <12
Topic Options
#61019 - 2001-12-14 01:15 PM Re: Automaticaly Archive each directory to a individual zip.
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11629
Loc: CA
Dear andreasfc,

Don't know... Please post your code so that we can look at what might be wrong, or causing a problem.

Top
#61020 - 2001-12-14 04:15 PM Re: Automaticaly Archive each directory to a individual zip.
andreasfc Offline
Fresh Scripter

Registered: 2001-12-13
Posts: 18
Oke here is the code.

It is creating zip files over and over until I press Control-C

break on
?
;
$basedir="E:\Applications\Kixtart\Test\*.*"
$filename=Dir($basedir)

WHILE ($filename <> "") AND (@error = 0)
IF ($filename <> ".") AND ($filename <> "..") AND (GetFileAttr($basedir+"\"+$filename) & 16)
;? $basedir+"\"+$filename
GOTO "END"
ENDIF
IF $filename = "." Or $filename = ".."
$filename=Dir()
GOTO LOOP1
ELSE
;? $basedir
;? $filename " - Directory Name"
GOSUB create_zip
$filename=Dir()
;? "GOSUB create_zip"
ENDIF
:LOOP1
LOOP
EXIT

:create_zip
$cmd=" wzzip -a -ex -rp "
$cmd=$cmd+ Chr (34) + "E:\Applications\Kixtart\test\$filename"+".zip" + Chr (34) +" "+ Chr (34) + "E:\Applications\Kixtart\test\$filename" + Chr (34)
SHELL '%comspec% /c $cmd '
;? $cmd
; "Create Zip String"
?
RETURN
:END

Thanx

Top
#61021 - 2001-12-15 01:05 PM Re: Automaticaly Archive each directory to a individual zip.
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11629
Loc: CA
Hi andreasfc,

I'm sorry, but you changed a LOT of the code. Here below is working code for your situation.

code:
break on
$pkzip_mode="add" ; "move"
$basedir="E:\Applications\Kixtart\Test"
$filename=Dir("$basedir")
WHILE ($filename <> "") AND (@error = 0)
IF ($filename <> ".") AND ($filename <> "..") AND (GetFileAttr($basedir+"\"+$filename) & 16)
GOSUB create_zip
ENDIF
$filename=Dir()
LOOP
EXIT
:create_zip
IF ($pkzip_mode = "add")
$cmd=" wzzip -a -ex -rP "
ELSE
$cmd=" wzzip -m -ex -rP "
ENDIF
$cmd=$cmd+' "$basedir'+'\'+LTRIM(RTRIM($filename))+'.zip" "$basedir'+'\'+'$filename'+'\*.*" '
SHELL '%comspec% /c $cmd' ; <++++++++++
RETURN

Copy this code into Word and then copy/paste into your text editor and save the file as a .kix file and it should work fine.

Top
#61022 - 2001-12-15 07:12 PM Re: Automaticaly Archive each directory to a individual zip.
andreasfc Offline
Fresh Scripter

Registered: 2001-12-13
Posts: 18
Hello NTDOC,

I tried the script and it worked
thanx, but it only packs files which are in the subdir.
So how can I do this for files in the sam directory?

Thanx

Top
#61023 - 2001-12-16 12:41 AM Re: Automaticaly Archive each directory to a individual zip.
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
andreasfc,
Since the enumeration of the DIRs, is my handywork, I'll speak to it. Read or reread my second post (fifth from the top) in this thread. There I try to explain what the code does. It was written to the requirement that PhoeniX put forth. If your requirement is different, the code can be changed.

The line "If ($Name <> ".") And ($Name <> "..") And (GetFileAttr($basedir+"\"+$name) & 16)" skips all parsed lines that dont match the requirements. Namely, it skips the DIR entries "." and ".." and also skips all lines that are not folders.

So, how to change the code depends on what you're trying to achieve. If you simply removed the folder check "(GetFileAttr($basedir+"\"+$name) & 16)", then every file encountered in $basedir would end up as an individual zip.

If, on the other hand, you want to zip the $basedir contents into just one zip file, then you don't even need the DIR enumeration. Just pass $basedir\*.* to the zip routine.

_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#61024 - 2001-12-16 02:44 AM Re: Automaticaly Archive each directory to a individual zip.
MCA Offline
KiX Supporter
*****

Registered: 2000-04-28
Posts: 5152
Loc: Netherlands, EU
Dear,

Your specification of variable $basedir is incorrect. Using \*.* has been
removed.
Also you are using a lot of GOTO statements which aren't necessary. Also we change
your code to reduce them. In our opinion is a script more readable without GOTO's.

code:

break on
;
$basedir="e:\Applications\Kixtart\Test"
$filename=Dir("$basedir")
WHILE ($filename <> "") AND (@error = 0)
IF ($filename <> ".") AND ($filename <> "..") AND (GetFileAttr($basedir+"\"+$filename) & 16)
; ? $basedir+"\"+$filename
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 ' ; <++++++++
? $cmd
RETURN



An output example can be for the "c:\windows" directory:
code:

wzzip -a -ex -rp "c:\windows\INF.zip" "c:\windows\INF"
wzzip -a -ex -rp "c:\windows\SYSTEM.zip" "c:\windows\SYSTEM"
wzzip -a -ex -rp "c:\windows\COMMAND.zip" "c:\windows\COMMAND"
wzzip -a -ex -rp "c:\windows\HELP.zip" "c:\windows\HELP"
wzzip -a -ex -rp "c:\windows\FONTS.zip" "c:\windows\FONTS"
wzzip -a -ex -rp "c:\windows\SendTo.zip" "c:\windows\SendTo"
wzzip -a -ex -rp "c:\windows\WANGSAMP.zip" "c:\windows\WANGSAMP"
wzzip -a -ex -rp "c:\windows\DESKTOP.zip" "c:\windows\DESKTOP"
wzzip -a -ex -rp "c:\windows\JAVA.zip" "c:\windows\JAVA"
wzzip -a -ex -rp "c:\windows\CONFIG.zip" "c:\windows\CONFIG"
wzzip -a -ex -rp "c:\windows\MEDIA.zip" "c:\windows\MEDIA"
wzzip -a -ex -rp "c:\windows\CURSORS.zip" "c:\windows\CURSORS"
wzzip -a -ex -rp "c:\windows\TEMP.zip" "c:\windows\TEMP"
wzzip -a -ex -rp "c:\windows\SYSBCKUP.zip" "c:\windows\SYSBCKUP"
wzzip -a -ex -rp "c:\windows\spool.zip" "c:\windows\spool"
wzzip -a -ex -rp "c:\windows\History.zip" "c:\windows\History"

We have comment the SHELL call to prevent an unexpected result during
a test run.
greetings.

_________________________
email scripting@wanadoo.nl homepage scripting@wanadoo.nl | Links | Summary of Site Site KiXforms FAQ kixtart.org library collection mirror MCA | FAQ & UDF help file UDF kixtart.org library collection mirror MCA | mirror USA | mirror europe UDF scriptlogic library collection UDFs | mirror MCA

Top
#61025 - 2001-12-18 04:29 AM Re: Automaticaly Archive each directory to a individual zip.
PhoeniX Offline
Fresh Scripter

Registered: 2000-11-01
Posts: 22
Loc: Brisbane, QLD, Australia
MCA,

I've tryed the code over and over, and I'm sure I understand it yet for me it will just roll through the routine and EXIT. I have no idear why, or can find a method to make it work.

code:
  
break on
;
$basedir="C:\windows"
$filename=Dir("$basedir")
WHILE ($filename <> "") AND (@error = 0)
IF ($filename <> ".") AND ($filename <> "..") AND (GetFileAttr($basedir+"\"+$filename) & 16)
? $basedir+"\"+$filename
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 ' ; <++++++++
? $cmd
RETURN

This is what I'm running for the sake of example and continuity I'm using C:\windows

This is the debug lines:
break on
$basedir="C:\windows"
$filename=Dir("$basedir")
WHILE ($filename <> "") AND (@error = 0)
IF ($filename <> ".") AND ($filename <> "..") AND (GetFileAttr($basedir+"\"+$fil
ename) & 16)
$filename=Dir()
LOOP
EXIT

I would say it can't find any directories.
The code would appear to work for everyone but me.

Extreamly bothered!!!

Phoe.

Top
#61026 - 2001-12-18 05:12 AM Re: Automaticaly Archive each directory to a individual zip.
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Phoe,

What version of kix you running ?

-Shawn

Top
#61027 - 2001-12-18 05:16 AM Re: Automaticaly Archive each directory to a individual zip.
PhoeniX Offline
Fresh Scripter

Registered: 2000-11-01
Posts: 22
Loc: Brisbane, QLD, Australia
Shawn,

Kix Details:
C:\kix>kix32 /?
>>> KiXtart 95 3.63
Windows 2000 / NT 4.x / Windows 9x (logon) script processor.
Usage : KIX32 [script1] [...] [$var=123]

Phoe

Top
#61028 - 2001-12-18 05:32 AM Re: Automaticaly Archive each directory to a individual zip.
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Hmmm... try this:


break on
;
$basedir="c:\windows"
$filename=dir("$basedir\*")
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 ' ; <++++++++
? $cmd
RETURN

Somethings fishy here though ...

-Shawn

[ 18 December 2001: Message edited by: Shawn ]

Top
#61029 - 2001-12-18 06:01 AM Re: Automaticaly Archive each directory to a individual zip.
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Ok - yeah - MCA hit the nail on the head in the first post of this page ...

Try the script above ^

-Shawn

Top
#61030 - 2001-12-18 06:16 AM Re: Automaticaly Archive each directory to a individual zip.
PhoeniX Offline
Fresh Scripter

Registered: 2000-11-01
Posts: 22
Loc: Brisbane, QLD, Australia
Shawn,

wow it worked!!!!!!
Thanks heaps all, now to make sure I understand it & why it work for others and not me.


Phoe

Top
#61031 - 2001-12-18 03:32 PM Re: Automaticaly Archive each directory to a individual zip.
MCA Offline
KiX Supporter
*****

Registered: 2000-04-28
Posts: 5152
Loc: Netherlands, EU
Dear,

We verify our code against kixtart 3.63 release and indeed code works diffe-
rent.
Only using Dir("c:\windows") means: search for file windows
in directory c:\.
With release 4.x it means: search for all entry in directory c:\windows.
Work around is: specify Dir("c:\windows\*.*".

code:

; Kixtart 3.63 + 4.x
;
break on
;
$basedir="e:\Applications\Kixtart\Test"
$filename=Dir("$basedir\*.*")
WHILE ($filename <> "") AND (@error = 0)
IF ($filename <> ".") AND ($filename <> "..") AND (GetFileAttr($basedir+"\"+$filename) & 16)
; ? $basedir+"\"+$filename
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 ' ; <++++++++
? $cmd
RETURN



An output example can be for the "c:\windows" directory:
code:

wzzip -a -ex -rp "c:\windows\INF.zip" "c:\windows\INF"
wzzip -a -ex -rp "c:\windows\SYSTEM.zip" "c:\windows\SYSTEM"
wzzip -a -ex -rp "c:\windows\COMMAND.zip" "c:\windows\COMMAND"


We have comment the SHELL call to prevent an unexpected result during
a test run.
PhoeniX "why it work for others and not me" we think "other persons are using it
in a kixtart 4.x environment.
greetings.
_________________________
email scripting@wanadoo.nl homepage scripting@wanadoo.nl | Links | Summary of Site Site KiXforms FAQ kixtart.org library collection mirror MCA | FAQ & UDF help file UDF kixtart.org library collection mirror MCA | mirror USA | mirror europe UDF scriptlogic library collection UDFs | mirror MCA

Top
Page 2 of 2 <12


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 2419 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.048 seconds in which 0.027 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org