; NextFile Example
; ----------------

; Build a small folder tree owned by this example
CreateDir "demo_files"
CreateDir "demo_files\saves"
file=WriteFile("demo_files\readme.txt")
WriteLine file,"Demo file one"
CloseFile file
file=WriteFile("demo_files\config.txt")
WriteLine file,"Demo file two"
CloseFile file

; Open the folder for reading - the handle feeds NextFile$
dir=ReadDir("demo_files")

Print "Listing of demo_files:"

; NextFile$ returns the next entry each call, moving forward only.
; "" means the folder is exhausted (the . and .. entries may appear too)
Repeat
    entry$=NextFile$(dir)
    If entry$="" Then Exit
    ; FileType tells folders (2) from files (1)
    If FileType("demo_files\"+entry$)=2 Then
        Print "  <DIR>  "+entry$
    Else
        Print "  file   "+entry$
    EndIf
Forever

; Always close the folder when you are done with it
CloseDir dir

; Clean up everything the example created
DeleteFile "demo_files\readme.txt"
DeleteFile "demo_files\config.txt"
DeleteDir "demo_files\saves"
DeleteDir "demo_files"
Print ""
Print "Cleaned up demo_files"

Print ""
Print "Press any key to close the example"
WaitKey

End
