Page 1 of 1 1
Topic Options
#44084 - 2003-08-15 01:21 AM How do I make this script continue.
PhoeniX Offline
Fresh Scripter

Registered: 2000-11-01
Posts: 22
Loc: Brisbane, QLD, Australia
Hey all, can someone please tell me why the script will not continue to report '? "Reported finds = " $finds ?' at the end of the script. At the moment the idea is to match directory names, from a text file. Then report them to $finds. Oh, itsdoes find matches as it also reports while running.

Thanks to the ppls examples I've used so far.

Phoe.

code:
  
cls break on
$file = "archlist.txt"
$countf = 0

$ = open(1,$file)
$line = readline(1)

;start with an initial array size of 5
dim $array[5]
$count = 0

while not @error

;let check to make sure you are not over the current array size,
;if we are increase the array size by 10

if $count = ubound($array)
redim preserve $array[ubound($array)+10]
endif

;add a line to the array
$array[$count] = $line

;increase our counter by 1
$count = $count + 1

;get the next line of text
$line = readline(1)

loop

$ = close(1)

;ok, time to trim back to array size to the actual size of the data.
if $count > 0
redim preserve $array[$count - 1]
else
;hmmm looks like no information was loaded... make sure your file
;is avaliable
$array = ""
endif

;just a simple check to show your data in the array...
for each $clientno in $array
; ? $clientno ?

GOSUB "find_dir"

NEXT

:find_dir
if len($clientno) <> 7
Exit
else
$dirno = $clientno
endif

$dirfnd = dir("c:\tmp\kix2001\clients\"+$dirno+"*")

if ($dirfnd <> ".") And ($dirfnd <> "..") And len($dirfnd); > 7 And GetFileAttr($basedir+"\"+$name) & 16)

? "Directory found: $dirfnd" ?
$finds = $finds+ ", " + $dirfnd
; GOSUB "zip_dir"

else

? "Directory not found: $dirno" ?
; Exit
endif
Return


:zip_dir
$filename = $dirfnd
$basedir="c:\tmp\kix2001\clients"

WHILE ($filename <> "") AND (@error = 0)
IF ($filename <> ".") AND ($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 ' ; <++++++++
; Return

? "Reported finds = " $finds ?


Top
#44085 - 2003-08-15 01:27 AM Re: How do I make this script continue.
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
not 100% sure but:
"Return" before it might have something to do with it.
more precisely, the return from find_dir.
once your script is done, it executes everything from top to bottom.
so it runs find_dir as normal code and the return makes the script exit before it never gets there.

not sure, but that's the memory I have left from kix 3.xx logics.
_________________________
!

download KiXnet

Top
#44086 - 2003-08-15 01:27 AM Re: How do I make this script continue.
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
I think it's a matter of variable scope. Try making $finds global.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#44087 - 2003-08-15 02:08 AM Re: How do I make this script continue.
PhoeniX Offline
Fresh Scripter

Registered: 2000-11-01
Posts: 22
Loc: Brisbane, QLD, Australia
Thanks for the prompt reply Lonkero & LLigetfa,

I've look again and removed the goto's and returns. If I remove the NEXT at the bottom it will report $finds in the loop. If I replace the NEXT it will not move on to '? "Reported finds = " $finds ? '

LLigetfa I thought $finds is global as its declaired like $GlobalVariable = 10 and not
DIM $LocalVariable
$LocalVariable = 10

Phoe

code:
 
cls break on
$file = "archlist.txt"
$countf = 0

$ = open(1,$file)
$line = readline(1)

;start with an initial array size of 5
dim $array[5]
$count = 0

while not @error

;let check to make sure you are not over the current array size,
;if we are increase the array size by 10

if $count = ubound($array)
redim preserve $array[ubound($array)+10]
endif

;add a line to the array
$array[$count] = $line

;increase our counter by 1
$count = $count + 1

;get the next line of text
$line = readline(1)

loop

$ = close(1)

;ok, time to trim back to array size to the actual size of the data.
if $count > 0
redim preserve $array[$count - 1]
else
;hmmm looks like no information was loaded... make sure your file
;is avaliable
$array = ""
endif

;just a simple check to show your data in the array...
for each $clientno in $array
; ? $clientno ?

if len($clientno) <> 7
Exit
else
$dirno = $clientno
endif

$dirfnd = dir("c:\tmp\kix2001\clients\"+$dirno+"*")

if ($dirfnd <> ".") And ($dirfnd <> "..") And len($dirfnd); > 7 And GetFileAttr($basedir+"\"+$name) & 16)

? "Directory found: $dirfnd" ?
$finds = $finds+ ", " + $dirfnd

else

? "Directory not found: $dirno" ?
; Exit
endif

NEXT

? "Reported finds = " $finds ?


Top
#44088 - 2003-08-15 02:19 AM Re: How do I make this script continue.
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Not sure what I was thinking. Thought that maybe vars in a gosub were local to the sub.

Give the script a go with 4.22b1 as there was a memory issue with Dir() that got addressed.
quote:
Fixes/enhancements in 4.22:
- Fixed: bug in Dir() could cause memory overwrite

http://www.kixtart.org/board/ultimatebb.php?ubb=get_topic;f=3;t=000412
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#44089 - 2003-08-15 02:24 AM Re: How do I make this script continue.
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
k, last thing left is:
code:
if len($clientno) <> 7
Exit

if your last entry in array is empty, it will never get to the point of showing as that exit makes it exit before that.

[ 15. August 2003, 02:27: Message edited by: Lonkero ]
_________________________
!

download KiXnet

Top
#44090 - 2003-08-15 03:02 AM Re: How do I make this script continue.
PhoeniX Offline
Fresh Scripter

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

that was it!!!!
Thankyou both so much for helping. Below is what I have ended up with. My next step is to use $finds and output it to a report at the end. Would I be better to use an array to collect the finds or splitting the $finds string?

Phoe.

code:
 
cls break on
$file = "archlist.txt"
$countf = 0

$ = open(1,$file)
$line = readline(1)

;start with an initial array size of 5
dim $array[5]
$count = 0

while not @error

;let check to make sure you are not over the current array size,
;if we are increase the array size by 10

if $count = ubound($array)
redim preserve $array[ubound($array)+10]
endif

;add a line to the array
$array[$count] = $line

;increase our counter by 1
$count = $count + 1

;get the next line of text
$line = readline(1)

loop

$ = close(1)

;ok, time to trim back to array size to the actual size of the data.
if $count > 0
redim preserve $array[$count - 1]
else
;hmmm looks like no information was loaded... make sure your file
;is avaliable
$array = ""
endif

;just a simple check to show your data in the array...
for each $clientno in $array
; ? $clientno ?

if len($clientno) = 7
$dirno = $clientno

$dirfnd = dir("c:\tmp\kix2001\clients\"+$dirno+"*")

if ($dirfnd <> ".") And ($dirfnd <> "..") And len($dirfnd); > 7 And GetFileAttr($basedir+"\"+$name) & 16)

? "Directory found: $dirfnd" ?
$finds = $finds+ ", " + $dirfnd

else

? "Directory not found: $dirno" ?
; Exit
endif

endif
NEXT

? "Reported finds = " $finds ?


Top
#44091 - 2003-08-15 03:34 AM Re: How do I make this script continue.
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
as long as you don't have 3000 entries in the find, it does not matter.
no real effect on speed or anything.
_________________________
!

download KiXnet

Top
#44092 - 2003-08-15 04:32 AM Re: How do I make this script continue.
PhoeniX Offline
Fresh Scripter

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

the string could get very long, but I want to save all the reporting of 'finds' and 'not finds' for the end? What would be the best method?

Phoe.

Top
#44093 - 2003-08-15 04:40 AM Re: How do I make this script continue.
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
you want what?
thought I said that it does not matter.
what you mean with end.

the long string can be about 32000 characters before it starts to matter.

having it as string is lot simpler (1 line less of code) but has the size limit.

array is fine and if you have no trouble writing it in array, do so.
_________________________
!

download KiXnet

Top
#44094 - 2003-08-15 02:59 PM Re: How do I make this script continue.
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
You should take a look at the UDF Forum, it contains UDFs to read a text file into an array and various DIR UDFs. You could also use WMI to enumerate all directories on a filesystem into a second array, maybe even applying filters, and/or use ASCAN to check for directory names in the arrays.
_________________________
There are two types of vessels, submarines and targets.

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
0 registered and 774 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.06 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