Discussion:
DIR$ Function
(too old to reply)
Robert Wolfe
2009-02-01 18:33:07 UTC
Permalink
Hi all!

I am using the latest PB/CC compiler and tried the following example from the help for DIR$:

DIM Listing$(1 TO 1000)
DIM x&, temp$
temp$ = DIR$("*.*", TO Listing(x&) )
WHILE LEN(temp$) AND x& < 1000 ' max = 1000
INCR x&
temp$ = DIR$(NEXT, TO Listing(x&) )
WEND

For some reason this would not allow the program to compile. In order to get what I want to
do working I had to use the following code:

SUB ShowConfigDir
DIM temp AS STRING
DIM t AS INTEGER
SHELL ENVIRON$("COMSPEC") + " /C dir /b /w *.cfg > tempdir"
OPEN "tempdir" FOR INPUT AS #1
WHILE NOT EOF(1)
LINE INPUT #1, temp
PRINT temp
WEND
CLOSE #1
KILL "tempdir"
END SUB

Now if there is a CORRECT way to do this using the DIR$ function, any pointers in that
direction would be greatly appreciated.
Michael Mattias
2009-02-01 21:44:44 UTC
Permalink
Post by Robert Wolfe
I am using the latest PB/CC compiler and tried the following example from
DIM Listing$(1 TO 1000)
DIM x&, temp$
temp$ = DIR$("*.*", TO Listing(x&) )
WHILE LEN(temp$) AND x& < 1000 ' max = 1000
INCR x&
temp$ = DIR$(NEXT, TO Listing(x&) )
WEND
For some reason this would not allow the program to compile. In order to
get what I want to
.... [snipped]
Now if there is a CORRECT way to do this using the DIR$ function, any pointers in that
direction would be greatly appreciated.
Using the TO form of DIR$ requires the target variable be of type DIRDATA.

You have a DIM Listing$() (with the dollar sign, making it a STRING array)
and TO Listing(X&) with the type unspecified for the array variable
Listing(), which of course does not exist because it's not the object of a
DIM or scope (LOCAL, STATIC, GLOBAL) variable declaration statement.

First thing you do is start using the '#DIM ALL' compiler directive, so
silly typing errors like this get flagged for you before you have to start
trying other things.

Second, when you do have to ask for help because a program will not compile,
you include the error message and the offending line of code.

Third, if that's really the way the example appears in the help - EXACTLY -
you send a "documentation bug report" to ***@powerbasic.com.
--
Michael C. Mattias
Tal Systems Inc.
Racine WI
***@talsystems.com
Loading...