Page 1 of 2 12>
Topic Options
#60999 - 2001-12-04 01:42 AM Automaticaly Archive each directory to a individual zip.
PhoeniX Offline
Fresh Scripter

Registered: 2000-11-01
Posts: 22
Loc: Brisbane, QLD, Australia
Greetings all.

I'm looking for a method to archive many directories that contain sub dirs. To many zip archives using each primary directories name.

Top
#61000 - 2001-12-04 02:55 AM Re: Automaticaly Archive each directory to a individual zip.
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Not sure I understand...

Assumptions:
Folder contains files and other folders.
You want to zip up files in folders but not the folders within folders.
You want the zip name to match the folder name.
You have access rights to all files and folders.

Questions:
Is this right?
Do you have nested folders?
Where do the zips go?
What about duplicate names?
What zip product do you intend to use and does is support a Command Line Interface or scripting?
Is there really a Santa Claus?

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

Top
#61001 - 2001-12-04 03:32 AM Re: Automaticaly Archive each directory to a individual zip.
PhoeniX Offline
Fresh Scripter

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

Thank you for a responce, I'll try make it more clear.

I have a directory structure that holds clients information. Each client has a directory that is named ((file No.) - (client name)) within each client dir are subdirs containing more info.

I need to pkzip each Client Dir (& sub dirs)
as individual client zip archives, using the primary directory name as the archive name.
eg. ((file No.) - (client name)).zip

WinZip has this function but one file at a time, when you click the RMB on the directory you can select "Add To..." it uses the "directory or file name".zip
I would like to automate the process, as I have 7000 to do.


Ta, Phoe.

Top
#61002 - 2001-12-04 05:17 AM Re: Automaticaly Archive each directory to a individual zip.
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Hello PhoeniX,

Please see this post for a batch file method that can be altered. http://kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic&f=2&t=002591


I would get a copy of the Command Line add-on for WinZip and use that.

You can then choose any files you want and do all from the command line.

Hopefully this is enough information to get you going.

Please post an update on your progress.

[ 04 December 2001: Message edited by: NTDOC ]

Top
#61003 - 2001-12-04 05:55 AM Re: Automaticaly Archive each directory to a individual zip.
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
OK, here's some KiX code to enumerate the folder names from the base dir. Since Dir() will also return the two folders '.' and '..', provision has been made. Also, I check to make sure they are folders with GetFileAttr(), ignoring files at that level. All you have left to do is to replace the line "? $basedir+"\"+$name" with whatever your zip utility uses for the CLI.


code:

break on

$basedir = "C:\Program Files"
$Name = Dir("$basedir")
While $Name <> "" and @ERROR = 0
If ($Name <> ".") And ($Name <> "..") And (GetFileAttr($basedir+"\"+$name) & 16)
? $basedir+"\"+$name
EndIf
$Name = Dir() ; retrieve next file
Loop

get $


[ 04 December 2001: Message edited by: LLigetfa ]

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

Top
#61004 - 2001-12-04 10:38 AM Re: Automaticaly Archive each directory to a individual zip.
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
There you go... Les is more of a KiX purist then I.
Top
#61005 - 2001-12-04 03:53 PM Re: Automaticaly Archive each directory to a individual zip.
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
EH DOC,
How's it going? Are you weaning yourself off of KiX, or has that move to WSH died?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#61006 - 2001-12-05 03:48 AM Re: Automaticaly Archive each directory to a individual zip.
MCA Offline
KiX Supporter
*****

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

We have made some modification to LLigetfa example.
We are using the command line version of PKZIP.
Also we are using "-ex" (best compression), "-r" (included also subdirectories)
and "-p" (included also pathnames).

code:

break on
$pkzip_mode="add" ; "move"
;
$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
IF ($pkzip_mode = "add")
$cmd=" pkzip -a -ex -r -p "
ELSE
$cmd=" pkzip -m -ex -r -p "
ENDIF
$cmd=$cmd+' "$basedir'+'\'+LTRIM(RTRIM($filename))+'.zip" "$basedir'+'\'+'$filename'+'\*.*" '
; SHELL '%comspec% /c $cmd' ; <++++++++++
? $cmd
RETURN


An output example can be:
code:

pkzip -a -ex -r -p "c:\windows\INF.zip" "c:\windows\INF\*.*"
pkzip -a -ex -r -p "c:\windows\SYSTEM.zip" "c:\windows\SYSTEM\*.*"
pkzip -a -ex -r -p "c:\windows\COMMAND.zip" "c:\windows\COMMAND\*.*"
pkzip -a -ex -r -p "c:\windows\HELP.zip" "c:\windows\HELP\*.*"
pkzip -a -ex -r -p "c:\windows\FONTS.zip" "c:\windows\FONTS\*.*"
pkzip -a -ex -r -p "c:\windows\SendTo.zip" "c:\windows\SendTo\*.*"
pkzip -a -ex -r -p "c:\windows\WANGSAMP.zip" "c:\windows\WANGSAMP\*.*"
pkzip -a -ex -r -p "c:\windows\DESKTOP.zip" "c:\windows\DESKTOP\*.*"
pkzip -a -ex -r -p "c:\windows\JAVA.zip" "c:\windows\JAVA\*.*"
pkzip -a -ex -r -p "c:\windows\CONFIG.zip" "c:\windows\CONFIG\*.*"
pkzip -a -ex -r -p "c:\windows\MEDIA.zip" "c:\windows\MEDIA\*.*"
pkzip -a -ex -r -p "c:\windows\CURSORS.zip" "c:\windows\CURSORS\*.*"
pkzip -a -ex -r -p "c:\windows\TEMP.zip" "c:\windows\TEMP\*.*"
pkzip -a -ex -r -p "c:\windows\SYSBCKUP.zip" "c:\windows\SYSBCKUP\*.*"
pkzip -a -ex -r -p "c:\windows\spool.zip" "c:\windows\spool\*.*"
pkzip -a -ex -r -p "c:\windows\History.zip" "c:\windows\History\*.*"
pkzip -a -ex -r -p "c:\windows\Temporary Internet Files.zip" "c:\windows\Temporary Internet Files\*.*"

We have comment the SHELL call to prevent an unexpected result during
a test run. Please modify it and remove ";" symbol.
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
#61007 - 2001-12-10 08:13 AM Re: Automaticaly Archive each directory to a individual zip.
PhoeniX Offline
Fresh Scripter

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

I'm very impressed at the responces, I did try out the examples but I'm unable to get MCA's version to run. It will not pass the while loop to process the :create_zip.
I understand a majority of the code, but this isat the end of my kix experiance.
(Sorta why I needed to post the question )

Would any of you be kind enough to help me diagnose it.

(idles..... - is there any #KIX on IRC anymore?)

Thank you all,

PhoeniX

Top
#61008 - 2001-12-10 10:50 AM Re: Automaticaly Archive each directory to a individual zip.
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Hello PhoeniX,

Please get and install the WinZip command line add-on assuming you already have WinZip v8.0 already installed.

WinZip Command Line Support Add-On Version 1.0 http://www.winzip.com/other.htm http://www.winzip.com/wzcline.htm http://www.winzip.com/getsitec.cgi

Then change this batch file to your folder locations.


code:
for /f "Tokens=*" %%i in ('dir /B D:\users') do c:\progra~1\winzip\wzzip.exe -rP D:\users\%%i.zip D:\users\%%i\*.*

HTH...

If you want or need a PURE KiXtart solution I'm sure Les or MCA can help you out further.

Top
#61009 - 2001-12-11 05:33 AM Re: Automaticaly Archive each directory to a individual zip.
MCA Offline
KiX Supporter
*****

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

First a remark: we send you by email both shareware programs PKZIP & PKUNZIP.

Secondly, some questions:
- are you using this script in another script?
- did you also remove the ";" symbol in the line ; ? $basedir+"\"+$filename
to see which directories were found and will be ZIPped?
- can you put the output of running our script on the board?
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
#61010 - 2001-12-11 10:48 AM Re: Automaticaly Archive each directory to a individual zip.
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Dear Phoenix, Les, and MCA

I have tested the modified code from MCA which was an adaption of the code by Les and it does work as written by MCA.

NOTES
1.
I'm not sure if PKZIP command line addon supports long file names or not as I have not downloaded it and tested it. The older PKZIP DID NOT support Long File Names.
The WinZip 8 Commnad Line addon does support long file names.
2.
My own personal preference would be to use -rP which would include the "complete" path of where the zip file came from.
3.
You MUST add the program wzzip to your PATH before running. It might be possible to add a direct call to wzzip via further modifications of the script, but easier to just add it to the PATH.

Minor modifications and confirmation that the code does run with KiXtart 2001 and WinZip Command Line Support Add-On 1.0 which requires WinZip v8.0

code:

break on
$pkzip_mode="add" ; "move"
;
$basedir="d:\users"
$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
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' ; <++++++++++
;? $cmd
RETURN

That said, both the Script and Batch file perform as intended.

Top
#61011 - 2001-12-12 03:20 AM Re: Automaticaly Archive each directory to a individual zip.
PhoeniX Offline
Fresh Scripter

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

I have set up the script and checked that
the zip software is pathed. I have removed the semicolon from $basedir+"\"+$filename.
(MCA)

The variables that I changed do work, but it doesn't display me the list of directories that would be zipped. I've taken NTDOCs' suggestions and installed winzip cmdline addons - wzzip (which is pathed)

When I run debug, the script just goes though the code to Exit and finishes. Which shows there is something the While that is not functioning.

Could someone also explain directory enumeration as well........?

PhoeniX

Top
#61012 - 2001-12-12 10:55 AM Re: Automaticaly Archive each directory to a individual zip.
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Phoenix,

Please post "YOUR" code so that we can see exactly what is going on. If you have your folders setup like my modified sample from MCA, it should run fine. It will not "show" you, it will create the zip files. Please read the help file for the command line add-on for the switches and their meanings.

Don't mix Mine, Les, and MCA's code as it may be causing problems unless you understand what is going on.

Waiting to here back from you with the posting of your actual code used. Maybe you have something odd going on that we can not see just by descriptions of the problem.

The Directory enumeration simply means that it will read through all the folders listed and place them in a variable that is used to perform commands against.

D:\USERS
\DAVE
\BILL
\STEVE

Enumeration would read them one by one and allow looping to perform commands on each one.

Oh! and by the way... This is my 700th post Hope to post many more...

[ 12 December 2001: Message edited by: NTDOC ]

Top
#61013 - 2001-12-12 10:23 PM Re: Automaticaly Archive each directory to a individual zip.
MCA Offline
KiX Supporter
*****

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

Indeed the PKZIP/PKUNZIP doesn't support long filenames. We forget it,
but you can replace the command by another tool which support long names.
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
#61014 - 2001-12-13 04:08 AM Re: Automaticaly Archive each directory to a individual zip.
MCA Offline
KiX Supporter
*****

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

We hope indeed you will post many more.
How is your WSH introduction going on, or has your management changed
their point of view?
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
#61015 - 2001-12-13 04:40 AM Re: Automaticaly Archive each directory to a individual zip.
PhoeniX Offline
Fresh Scripter

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

well I've produced this, I'm sorry if I've butchered some of your work. Its the only way I'm going to learn the more difficult stuff.
(hope this inserts correctly)

code:
  
break on
?
;
$basedir="c:\kix\springwood\File Archive 2001\*.*"
$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) + "C:\kix\springwood\$filename"+".zip" + Chr (34) +" "+ Chr (34) + "C:\kix\springwood\File Archive 2001\$filename" + Chr (34)
SHELL '%comspec% /c $cmd '
;? $cmd
; "Create Zip String"
?
RETURN
:END



yes it works.............
Phoe.

Top
#61016 - 2001-12-13 05:56 AM Re: Automaticaly Archive each directory to a individual zip.
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
butchered? BUTCHERED? B U T C H E R E D?

I'm sorry... I'm surprised it works. You need to develop an understanding of what the code actually does, rather than just butcher it until you get results.

If you are to learn and advance to more difficult stuff as you put it, and I was your teacher, I'd make you do it all over.

Please don't get discouraged. It is not my intention to ridicule.

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

Top
#61017 - 2001-12-13 09:11 AM Re: Automaticaly Archive each directory to a individual zip.
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Butchered? Where is the Texas Chainsaw Masacare guy when you need him.

Pheonix, I think all that Les is meaning to say is that the spacing and indentation of code helps you to follow what is going on.

Kind of like IF may start line without indentation. Then the command you want to run if the IF statement is true would go on the next line but would be indented with at least a couple of spaces. Then the ENDIF or an ELSE would line up with the IF

The same goes for all the other code as well. Take a look at "most" of the code on the board and you should see a pattern. It does not have to be exactly like everyone elses, but similar spacing makes it easier to read and decode by yourself and others.

Hope this helps explain why.


MCA
Well I'm not sure what is going on. I'm supposed to be able to use KiXtart till we get into Active Directory, then I'm supposed to use VBS via WSH. However, I think KiXtart may have given me a lead up to another position or job with Corporate. I hear through the grapevine (means here-say, maybe not true) that Corporate is wanting me to do some scripting for them. I would assume KiXtart, since I don't have VBS experience. I'll let you know as I learn more. Thanks for the good words.

NTDOC...

[ 13 December 2001: Message edited by: NTDOC ]

Top
#61018 - 2001-12-13 03:31 PM Re: Automaticaly Archive each directory to a individual zip.
andreasfc Offline
Fresh Scripter

Registered: 2001-12-13
Posts: 18
I tried the script and it keeps running and zipping all the files over and over, what dir I do wrong?
I only changed the directory.

Top
Page 1 of 2 12>


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

Who's Online
1 registered (Allen) and 466 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.074 seconds in which 0.024 seconds were spent on a total of 13 queries. Zlib compression enabled.

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