Page 1 of 1 1
Topic Options
#127334 - 2004-10-03 02:44 PM checking folder
mbu10 Offline
Fresh Scripter

Registered: 2004-09-08
Posts: 27
hi guys
looking if some one could help me with this
looking to check a folder for 6 files(which i would no the name)
now if any files are missing extract them from a zip file somewhere else on another drive
then run a shell on the files that were missing only

thanks

Top
#127335 - 2004-10-03 03:23 PM Re: checking folder
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Code:
break on

dim $folder, $file, $files
$folder = 'C:\temp\'
$files = 'file1.ext','file2.ext','file3.ext','file4.ext','file5.ext','file6.ext'
for each $file in $files
if not exist($folder + $file)
'put your ZIP CLI command here' ?
shell $folder + $file
endif
next



Edited by Les (2004-10-03 03:52 PM)
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#127336 - 2004-10-03 03:25 PM Re: checking folder
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Here's a quick template script for doing twoor more files like this, just replace the ? lines with shell statements that extract and work on the files:

Code:

break on

$folder = "."

$files = "x.tmp", "y.tmp", "z.tmp"

for each $file in $files

if exist($folder + "\" + $file) = 0

? "pkunzip $file from somwhere to $folder\$file"
? "run shell on $folder\$file"

endif

next



Its a start,

-Shawn

Top
#127337 - 2004-10-03 03:33 PM Re: checking folder
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Eh Shawn,
I was quicker, my script "explicit" and NoVarsInStrings" compliant, but with one small bug.

shell $file

should be:
shell $folder + $file
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#127338 - 2004-10-03 07:45 PM Re: checking folder
mbu10 Offline
Fresh Scripter

Registered: 2004-09-08
Posts: 27
been tryint htis but unzips all the files any reason why ?
been working for a couple of hours cannot figure why is doing them al


here

$folder = "C:\foldera"

$files = "$isaname1", "$isaname2", "$isaname3", "$isaname4", "$isaname5"

for each $file in $files

if exist($folder + "\" + $file) = 0

Shell "%COMSPEC% /C C:\kix\pkzipc.exe -extract C:\foldera\isafile.zip "$files" $folder\$file"
? "run shell on $folder\$file"

endif

next




thanks

Top
#127339 - 2004-10-03 08:04 PM Re: checking folder
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Hmmm... since you decided to use Shawn's code instead of mine, I will let him answer.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#127340 - 2004-10-03 08:07 PM Re: checking folder
mbu10 Offline
Fresh Scripter

Registered: 2004-09-08
Posts: 27
well it seemed easier for me to understand
Top
#127341 - 2004-10-03 08:11 PM Re: checking folder
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Well, see a couple problems.

Shell "%COMSPEC% /C C:\kix\pkzipc.exe -extract C:\foldera\isafile.zip "$files" $folder\$file"

You got double-quotes embedded in double quotes, so get rid of those, plus your using the "$files" variable, instead of the $file variable, so maybe it would work better like this:

Shell ' %COMSPEC% /C C:\kix\pkzipc.exe -extract C:\foldera\isafile.zip "$file" "$folder\$file" '

-Shawn

Top
#127342 - 2004-10-03 08:13 PM Re: checking folder
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Quote:

well it seemed easier for me to understand



How is:
if exist()=0

easier than:
if not exist()

Actually, it's not because you chose his version, it's because you didn't say thank you.

Hint: There are several FAQs on SHELL and the use of quotes. Also, I am not familiar with your ZIP CLI, but I highly doubt you can pass an array to it.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#127343 - 2004-10-03 08:16 PM Re: checking folder
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Shawn,
Again with the vars in strings. tsk, tsk
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#127344 - 2004-10-03 08:23 PM Re: checking folder
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
hehee, sorry my boo.
Top
#127345 - 2004-10-03 08:58 PM Re: checking folder
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11629
Loc: CA
Hmmm... thinking you are also using the old DOS PKUNZIP which only handles 8.3 file structure. (not sure, just a guess)

Please make sure you are using the WinZip 9 compliant Command Line tools which support long file names.

Also take a look at this posting which might be of interest or help you further.

Recursive Zip
http://www.kixtart.org/ubbthreads/showflat.php?Cat=&Number=75192

Top
#127346 - 2004-10-03 09:07 PM Re: checking folder
mbu10 Offline
Fresh Scripter

Registered: 2004-09-08
Posts: 27
thanks for all the help guys but still not working right
the following code is running fine extracts files to the correct path but is extracting them all and not just the files i need any ideas?


Dim $folder, $file, $files
$folder = 'C:\foldera\'
$files = '$isaname1','$isaname2','$isaname3','$isaname4','$isaname5'
For Each $file In $files
If NOT Exist($folder + $file)
Shell '%COMSPEC% /C C:\kix\WZUNZIP.exe -e C:\foldera\isafile.zip C:\foldera\"$file" C:\foldera\ '
Shell $folder + $file
EndIf
Next


thanks again

Top
#127347 - 2004-10-03 09:19 PM Re: checking folder
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11629
Loc: CA
You need to build a list of the files you want to extract. Using simply the -e tells WinZip to extract all files.

From the manual
Quote:

-@listfile Create a file listing all the files that would be unzipped if this option were not specified. Hint: remember to use the leading dash to create a list. Leave out the leading dash to use a list of files in a WZUNZIP command.



Copyright © 2004 WinZip Computing, Inc. All rights reserved.




Notice though that KiXtart using the @ sign as well so you will need to double up to use the @ sign in your code. -@@

Give that a try and let us know how it goes. I see now that you're using the correct version of Command Line "WZUNZIP.EXE"

Quote:

Examples

wzunzip test.zip

Extracts all files from Test.zip to the current directory.

wzunzip test.zip abc.txt

Extracts abc.txt from test.zip.

wzunzip -d test.zip

Extracts all files from Test.zip, recreating the directory structure from folder information stored in the Zip file. New directories are created if necessary. Hint: if folder information is stored in the Zip file, you will almost always want to use the -d option.

wzunzip -d test.zip c:\docs\

Extracts all files from Test.zip, recreating the directory structure from folder information stored in the Zip file. The files are stored under C:\DOCS. For example, if the file One.doc has no folder information in the Zip file, it would be stored as C:\Docs\One.doc; if the file Two.doc is stored in the Zip file with the folder Budget\, it would be stored as C:\Docs\Budget\Two.doc.

wzunzip test.zip @files.lst

Extracts from test.zip all files that are listed in the text file files.lst.

wzunzip -v test.zip

Lists contents of Test.zip.

wzunzip -v test.zip *.txt

Lists all files with a .txt extension in test.zip.

Copyright © 2004 WinZip Computing, Inc. All rights reserved.



Top
#127348 - 2004-10-03 09:21 PM Re: checking folder
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Create ahte proper command line string as a string before passign it to the SHELL command. You cna the print the string to the screen to see why it fails. Your use of vars in strings is one reason to why it fails.
_________________________
There are two types of vessels, submarines and targets.

Top
#127349 - 2004-10-03 09:37 PM Re: checking folder
mbu10 Offline
Fresh Scripter

Registered: 2004-09-08
Posts: 27
Just a thought whan i am tying to unzip and i am saying which file to unzip in the "file" part would this not pass the single file value to winzip

it just that after i have unzipped the single file which does not exist i need to run another shell command on it stright away then start testing for any other missing files
thanks again
i have passed varibles to winzip before so stating a $file into winzip would it not just pass the single varible to winzip and not the entire files varible(has all the files in it
thanks
martin

Top
#127350 - 2004-10-03 11:56 PM Re: checking folder
mbu10 Offline
Fresh Scripter

Registered: 2004-09-08
Posts: 27
ok this is the only way i could do it
only ever going to be looking for 5 files in a certain directory
and this is the code i found does now work

bit long winded and sure better way of doing it but i know it works
thanks


;This check to see if files are in the correct folder for the isa files
;if they are not it extracts them from the zip file then runs the gawk file
;to the correct folder and sorts them

If NOT Exist('C:\foldera\$isaname1')
Shell '%COMSPEC% /C C:\kix\WZUNZIP.exe -e C:\foldera\isafile.zip "$isaname1" C:\foldera\ '
Shell 'need the gawk command in here to make sure is done right then goes to next zip'
Else
? "SORRY NOT COPYING FILE EXISTS"
EndIf

If NOT Exist('C:\foldera\$isaname2')
Shell '%COMSPEC% /C C:\kix\WZUNZIP.exe -e C:\foldera\isafile.zip "$isaname2" C:\foldera\ '
Shell 'need the gawk command in here to make sure is done right then goes to next zip'
Else
? "SORRY NOT COPYING FILE EXISTS"
EndIf

If NOT Exist('C:\foldera\$isaname3')
Shell '%COMSPEC% /C C:\kix\WZUNZIP.exe -e C:\foldera\isafile.zip "$isaname3" C:\foldera\ '
Shell 'need the gawk command in here to make sure is done right then goes to next zip'
Else
? "SORRY NOT COPYING FILE EXISTS"
EndIf

If NOT Exist('C:\foldera\$isaname4')
Shell '%COMSPEC% /C C:\kix\WZUNZIP.exe -e C:\foldera\isafile.zip "$isaname4" C:\foldera\ '
Shell 'need the gawk command in here to make sure is done right then goes to next zip'
Else
? "SORRY NOT COPYING FILE EXISTS"
EndIf

If NOT Exist('C:\foldera\$isaname5')
Shell '%COMSPEC% /C C:\kix\WZUNZIP.exe -e C:\foldera\isafile.zip "$isaname5" C:\foldera\ '
Shell 'need the gawk command in here to make sure is done right then goes to next zip'
Else
? "SORRY NOT COPYING FILE EXISTS"
EndIf


Top
#127351 - 2004-10-04 12:30 AM Re: checking folder
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11629
Loc: CA
Well if it is ONLY 5 files, why even keep them in a zip file. Just store the files in a folder uncompressed and copy them over as needed. NO WinZip involved.

Top
#127352 - 2004-10-04 01:00 AM Re: checking folder
mbu10 Offline
Fresh Scripter

Registered: 2004-09-08
Posts: 27
well they are isa log files each one is 1.7 gig in size but when zipped the are only 2% of original size
have 17 of them (one for every server)
so cannot just copy 34-50 gig over the network but once zipped which happen at every isa server before transfer
then need to check on the logging server to check if the files are there (copy them from the zip file if they are not) before i gawk them into net tracker

Top
#127353 - 2004-10-04 08:33 AM Re: checking folder
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11629
Loc: CA
Here is some smaller/cleaner code that should perform the task just fine. Let me know how it works out. This code should be NoVarInStrings compliant.

Copy the code and paste it to Wordpad, then copy it from Wordpad and paste it to notepad or other text editor and save the file.

NOTE This is basically the code that Les and Shawn laid out for you already. I simply placed it into a full working code example.

Code:
Break On

Dim $SO,$Folder,$File,$FileList
$SO=SetOption('Explicit','On')
$SO=SetOption('NoVarsInStrings','On')
$Folder='C:\FOLDERA\'
$FileList='file1.txt','file2.txt','file3.txt','file4.txt','file5.txt'

For Each $File In $FileList
If Not Exist($Folder + $File)
Shell '%COMSPEC% /C C:\kix\WZUNZIP.exe -e ' + $Folder + 'isafile.zip ' + $File + ' ' + $Folder + ' >NUL 2>NUL'
EndIf
Next




SPACING OF QUOTES IS IMPORTANT

Top
Page 1 of 1 1


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

Who's Online
1 registered (Allen) and 483 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.073 seconds in which 0.025 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