|
Post by donnybowers on May 13, 2021 5:12:50 GMT -5
Here's my program:
dim f$(500) files #dir, "F:\RunBASICwin\projects\Faith_project\*" numFiles=0 while #dir hasAnswer() numFiles=numFiles+1 #dir nextFile$() if #dir isdir() then f$(numFiles)="[";#dir name$();"]" end if wend
files #dir, "F:\RunBASICwin\projects\checkbox_project\*" while #dir hasAnswer() numFiles=numFiles+1 #dir nextFile$() if #dir isdir() then else f$(numFiles)=#dir name$() end if wend
for i=1 to numFiles print str$(i);" - ";f$(i) next i
Here's what it produces:
How do I get rid of the blank lines?
|
|
|
Post by donnybowers on May 13, 2021 5:25:35 GMT -5
I was able to make it work with this modification; but it doesn't seem like you should have to do this. Am I missing something?
dim f$(500) files #dir, "F:\RunBASICwin\projects\Faith_project\*" numFiles=0 while #dir hasAnswer() #dir nextFile$() if #dir isdir() and #dir name$()<>"" then '--TEST FOR NULL STRING numFiles=numFiles+1 f$(numFiles)="[";#dir name$();"]" end if wend
files #dir, "F:\RunBASICwin\projects\checkbox_project\*" while #dir hasAnswer() #dir nextFile$() if #dir isdir() then else if #dir name$()<>"" then '--TEST FOR NULL STRING numFiles=numFiles+1 f$(numFiles)=#dir name$() end if end if wend
for i=1 to numFiles print str$(i);" - ";f$(i) next i
Produces:
|
|
|
Post by StefanPendl on May 13, 2021 7:15:03 GMT -5
The following code works without the need to add additional conditions. It also only advances the counter if an item is added to the array. The array is sized to the amount of returned items.
files #dir, ProjectsRoot$; "\program1_project\*"
dim f$(#dir rowcount())
numFiles = 0
while #dir hasAnswer() #dir nextFile$()
if #dir isdir() then numFiles = numFiles + 1
f$(numFiles) = "["; #dir name$(); "]" end if wend
#dir reset()
while #dir hasAnswer() #dir nextFile$()
if not(#dir isdir()) then numFiles = numFiles + 1
f$(numFiles) = #dir name$() end if wend
for i = 1 to numFiles print using("###", i); " - "; f$(i) next
end
|
|
|
Post by donnybowers on May 13, 2021 14:41:49 GMT -5
Thank you Stefan. It works perfectly I'll have to study this example. I love the fact that it sets the array to just the right size and doesn't waste memory. I need to learn these tricks to save server resources.
|
|