#75226 - 2003-05-30 07:57 PM
array / dir bug
|
Christophe-
Fresh Scripter
Registered: 2003-04-28
Posts: 5
|
Hi, This little script illustrates the problem. In my script I need to use the dir command after the array declaration.
Regards, Christophe.
$path="C:\"
;count the number of files in the dir $c = 0 $f = Dir("$path\*.txt") While @error = 0 $c = $c + 1 $f = Dir() Loop
;declare the array Global $array[$c,1]
;check the array size ? "-1-" ? Ubound($array,1) ? Ubound($array,2)
;check insert into array $array[0,0]="test"
;this is the command that screws up my array ! $FileName = Dir("$path\*.txt")
;Check the array size (at execution dimension 2 size is wrong) ? "-2-" ? Ubound($array,1) ? Ubound($array,2)
;Check insert into array (at execution time I have an out of bound error) $array[0,0]="test" [ 30. May 2003, 22:20: Message edited by: Christophe- ]
|
|
Top
|
|
|
|
#75228 - 2003-05-30 09:15 PM
Re: array / dir bug
|
Christophe-
Fresh Scripter
Registered: 2003-04-28
Posts: 5
|
Hi, Maybe I was not clear enough. My problem is not how to deal with dirlist or dirplus but the fact that using the dir command is ruining the array I use in the same script.
May someone please run this script and find if they have the same error I have commented here ?
|
|
Top
|
|
|
|
#75230 - 2003-05-30 10:19 PM
Re: array / dir bug
|
Christophe-
Fresh Scripter
Registered: 2003-04-28
Posts: 5
|
Ok for the $x. I did a quick copy and paste from my main script and I forgot a part of it. [I corrected it it the main post] Anyway this is not important for the test.
Here is my output: -1- 10 1 -2- 10 193
I also have the error: array reference out of bounds.
If I remove the $FileName = Dir("$path\*.txt") I obtain:
-1- 10 1 -2- 10 1
And I can write in the array without problem. [ 30. May 2003, 22:21: Message edited by: Christophe- ]
|
|
Top
|
|
|
|
#75236 - 2003-06-02 05:10 PM
Re: array / dir bug
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
I take it all back. I'd definately report this as a bug, Christophe.
It's really weird.
Simplest I can make the code is:
code:
$f = Dir("*",0) While @error = 0 $f = Dir(,0) Loop
;declare the array Global $array[10,99]
;check the array size "[1] Array ubound should be 99: " Ubound($array,2) ? $f = Dir("*",0) "[2] Array ubound should be 99: " Ubound($array,2) ?
This fails with 4.20.
Interestingly,
- If you use index 0 with the first Dir() and index 1 with the second you don't get the problem.
- If you don't exhaust the first loop you don't get the problem.
- If you have more than 2 array dimensions you don't get the problem.
{EDIT} Update - Fails with latest 4.21 too. {/EDIT} [ 02. June 2003, 17:17: Message edited by: Richard H. ]
|
|
Top
|
|
|
|
#75239 - 2003-06-02 09:03 PM
Re: array / dir bug
|
Christophe-
Fresh Scripter
Registered: 2003-04-28
Posts: 5
|
Hi Guys, Thank you for the great support. I have found a way to go around the problem (declaring the array at the start of the script and making a function to count the number of files). However I think that there is a bug as some people could reproduce the problem. I hope someone will find an explanation or a fix for the other users that may encounter the same issue.
I have to post a new message as now I have another problem [edit] I think I won't need to post as I'm in my way to find a solution to my problem ![[Smile]](images/icons/smile.gif) [ 02. June 2003, 21:36: Message edited by: Christophe- ]
|
|
Top
|
|
|
|
#75240 - 2003-06-03 09:31 AM
Re: array / dir bug
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
quote: Richard, did you try moving the global declaration to the beginning of the script?
No, because I was determining whether or not there is a bug in place rather than a way of avoiding it.
It appears that there is, and it may be significant as it implies that there is uninitialised memory used somewhere.
It needs to be reported as a bug as it may impact more than simply global variable declaration.
quote: Looks like a DIR() problem whne restarting the DIR enumeration with the same enumeration handle as this works:
Yes, see the first bullet point in my last post
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 837 anonymous users online.
|
|
|