Problem with the FILES statement

new BookmarkLockedFalling
donnybowers
Junior Member
**

donnybowers Avatar

My website was created in the mid 2000s. Unfortunately I lost the code somehow.
Posts: 70Male

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:

1 -
2 -
3 - [versions]
4 -
5 -
6 - checkbox.bas
7 -
8 - workingversion.xml


How do I get rid of the blank lines?
Any code I share on this forum is released to the public domain and may be used freely any way you like unless for some reason I specifically indicate otherwise in the post.
donnybowers
Junior Member
**

donnybowers Avatar

My website was created in the mid 2000s. Unfortunately I lost the code somehow.
Posts: 70Male

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:

1 - [versions]
2 - checkbox.bas
3 - workingversion.xml
Last Edit: May 13, 2021 5:29:16 GMT -5 by donnybowers
Any code I share on this forum is released to the public domain and may be used freely any way you like unless for some reason I specifically indicate otherwise in the post.
StefanPendl
Global Moderator
*****

StefanPendl Avatar

Run for BASIC ...
Posts: 945

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
[b]Stefan[/b] - [a href=http://stefanpendl.runbasichosting.com/]Homepage[/a][br][br][b]Please give credit if you use code I post, no need to ask for permission.[/b][br][br]Run BASIC 1.01, Fire-/Waterfox (IE11, Edge), Windows 10 Professional x64, Intel Core i7-4710MQ 2.5GHz, 16GB RAM
donnybowers
Junior Member
**

donnybowers Avatar

My website was created in the mid 2000s. Unfortunately I lost the code somehow.
Posts: 70Male

Last Edit: May 13, 2021 14:42:32 GMT -5 by donnybowers
Any code I share on this forum is released to the public domain and may be used freely any way you like unless for some reason I specifically indicate otherwise in the post.