Lance is preallocating array space in blocks of 100 elements, for efficiency
reasons. That's what the IF i& MOD 100 line takes care of.
------------------
Tom Hanlin
PowerBASIC Staff
Announcement
Collapse
No announcement yet.
Directory Code Question
Collapse
X
-
Greetings Lance and Tom!
Lance:
why do you need to go through the list twice?
Code:DirList$(i%) = File$ 'should be: DirList$(i&) = File$
Code:IF i& MOD 100 = 0 THEN REDIM PRESERVE DirList$(i& + 100)
Many thanks for the suggestions.
Don Ewald
mailto:[email protected][email protected]</A>
Leave a comment:
-
The "." and ".." entries are pseudo-directories. You'll get them back any time
you ask for a list of files including directories, except in the root directory.
The "." indicates the current directory, and ".." the directory above. If you
don't want to see these entries, you need to filter them out. Be sure to compare
specifically with "." and "..", though-- it's quite legal for a long filename to
begin with a ".".
You may not want to use the search mask "*.*". With the 8.3 search mechanism,
this returns all files. With LFN search, though, this may return only files with
"." in the name-- the "." is not a special-case character in quite the way it
used to be. To return all files using an LFN search pattern, just "*" is fine.
------------------
Tom Hanlin
PowerBASIC Staff
Leave a comment:
-
Donald, why do you need to go through the list twice?
Try this method (untested, written on-line):
Code:... OPEN "dir.lst" for OUTPUT as #1 DIM DYNAMIC DirList$(0) i& = 0 File$ = LfnDirFirst$("*.*", &h77) WHILE LEN(File$) PRINT #1, File$ IF i& MOD 100 = 0 THEN REDIM PRESERVE DirList$(i& + 100) DirList$(i%) = File$ INCR i& File$ = LfnDirNext$ WEND DECR i& ' valid subscripts will be (0) to (i& - 1) ' If i& < 0 then there were no files matching the spec REDIM PRESERVE DirList$(MAX(0,i&)) CLOSE #1 ...
------------------
Lance
PowerBASIC Support
mailto:[email protected][email protected]</A>
Leave a comment:
-
Directory Code Question
Greetings All!
I'm working on a crazy program and I've run into a problem. I'm using Hans Lunsing's PBLFN32 package and PowerBasic 3.5 for DOS. Whenever I bring the directory list into the array "DirList" I get some useless files that I don't need. I've extracted the code segment from the program and edited it for your perusal:
Code:$INCLUDE "lngfnam2.bi" $LINK "lngfnam2.pbu" 'Preinitialize data array File$ = LfnDirFirst$( "*.*", &h77 ) I& = 0 WHILE len( File$ ) > 0 I& = I& + 1 File$ = LfnDirNext$ WEND LI& = I& - 2 DIM DirList$( I& ) OPEN "dir.lst" for OUTPUT as #1 'Enter data into the array I& = 0 File$ = LfnDirFirst$( "*.*", &h77 ) WHILE len( File$ ) > 0 DirList$( I& ) = File$ PRINT #1, File$ File$ = LfnDirNext$ I& = I& + 1 WEND CLEAR CLOSE #1 END
Also, on another note, is there a better way to create and fill the array than the one that I used? I use this method twice and the second time takes a bit longer as I'm inputting a large delimited file of variable records. I'll probably delve into some more questions as they crop up.
Don Ewald
mailto:[email protected][email protected]</A>
Tags: None
Leave a comment: