Author Topic: Enumerating a directory  (Read 1535 times)

Offline John

  • Forum Support / SB Dev
  • Posts: 2747
    • ScriptBasic Open Source Project
Enumerating a directory
« on: January 07, 2014, 10:45:33 PM »
I stopped by the Jose Roca forum 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

SB Docs: Listing Files



« Last Edit: January 07, 2014, 11:01:35 PM by John »