All BASIC

BASIC Developer & Support Resources => Scripting Languages => Topic started by: John on January 07, 2014, 10:45:33 PM

Title: Enumerating a directory
Post by: John on January 07, 2014, 10:45:33 PM
I stopped by the Jose Roca forum (http://www.jose.it-berater.org/smfforum/index.php?topic=4927.msg20442;topicseen) and notice a thread about using the COM FileSystemObject to enumerate files. Why is everything that Microsoft creates comes with an extra layer of difficulty?

Here is a quick utility I put together in ScriptBasic to print all the .c files in a given directory.

Code: [Select]
cmd = COMMAND()

fn = FREEFILE
OPEN DIRECTORY cmd PATTERN "*.c" OPTION sbCollectFiles AND SbSortByName AND SbSortAscending AS #fn
RESET DIRECTORY #fn
GOSUB READ_DIR
CLOSE DIRECTORY #fn
END

READ_DIR:

FName = NEXTFILE(fn)
IF FName = undef THEN RETURN
PRINT FName & "\n"
GOTO READ_DIR

jrs@laptop:~/sb/sb22/test$ scriba dirc.sb ~/brandy_u64/src
assign.c
brandy.c
commands.c
convert.c
editor.c
emulate.c
errors.c
evaluate.c
fileio.c
functions.c
geom.c
graphsdl.c
heap.c
iostate.c
keyboard.c
lvalue.c
mainstate.c
miscprocs.c
riscos.c
simpletext.c
stack.c
statement.c
strings.c
textgraph.c
textonly.c
tokens.c
variables.c
jrs@laptop:~/sb/sb22/test$

If your interested in the SB directory reading feature set, here are a couple URLs.

Tutorial: Reading a directory (http://www.scriptbasic.org/forum/index.php/topic,133.0.html)

SB Docs: Listing Files (http://www.scriptbasic.org/docs/ug/ug_12.14.html)