Author Topic: Browsing Directories / files using Steve´s library  (Read 302 times)

Offline Petr

  • I am instructed.
Browsing Directories / files using Steve´s library
« on: July 08, 2018, 07:57:14 AM »
Hi, I'm just very limited in time, so I write this program for longer than usual. I just did not get to test it in Linux. Select and run any file. Quit it using Esc. Query for Steve: Exists a program that returns disk names usable in  both OS - windows and linux?

Code: [Select]
'files/directories list using Steve library (u.s. chars only)
DECLARE CUSTOMTYPE LIBRARY ".\direntry"
    FUNCTION load_dir& (s AS STRING)
    FUNCTION has_next_entry& ()
    SUB close_dir ()
    SUB get_next_entry (s AS STRING, flags AS LONG, file_size AS LONG)
END DECLARE
SCREEN _NEWIMAGE(800, 600, 32)


start:


REDIM Dir(0) AS STRING, File(0) AS STRING

IF LEN(runit$) THEN GetFileList runit$, Dir(), File() ELSE GetFileList _CWD$, Dir(), File()
REDIM All(UBOUND(dir) - 1 + UBOUND(file)) AS STRING

i = 0


FOR AllLoader = LBOUND(dir) + 2 TO UBOUND(dir) '                     i need not "." in list
    IF LEN(Dir(AllLoader)) THEN All(i) = Dir(AllLoader): i = i + 1
NEXT
FOR AllLoader = LBOUND(file) TO UBOUND(file)
    IF LEN(File(AllLoader)) THEN All(i) = File(AllLoader): i = i + 1
NEXT




DIRcount = UBOUND(dir) - 1
FILEcount = UBOUND(file)


DO
    CLS
    runit$ = Browse$(All(), 10, 10, 20, 10, DIRcount) 'array  contains files/directories names, this list X start coordinate, this list Y start coordinate, This list lenght (300 pixel lenght), 30 records in this list to view), return file/folder/"..", "." name which is selected
    IF runit$ = "---E" THEN END
    IF RIGHT$(runit$, 5) = ".DIR." THEN
        runit$ = LEFT$(runit$, LEN(runit$) - 5)
        CHDIR runit$: GOTO start
    END IF
    IF RIGHT$(runit$, 2) = ".." THEN CHDIR "..": GOTO start
    SHELL _DONTWAIT runit$
LOOP



FUNCTION Browse$ (arr() AS STRING, X, Y, lenght, height, numDirs)
    ListColor& = _RGB32(166, 244, 244)
    InPosColor& = _RGB32(67, 72, 238)
    DirColor& = _RGB32(238, 22, 28)
    Lb = 1
    Le = 20
    IF INSTR(1, _OS$, "WINDOWS") THEN sel$ = CHR$(92)
    IF INSTR(1, _OS$, "LINUX") THEN sel$ = "/"
    First = 1
    DO
        K& = _KEYHIT
        oldposx = posx
        IF First THEN oldposx = -1: First = 0
        SELECT CASE K&
            CASE 18432: posx = posx - 1: GU = 1: GD = 0 'marks: Go down disabled, go up enbabled
            CASE 20480: posx = posx + 1: GU = 0: GD = 1 'marks: Go down enabled, go up disabled
            CASE 13: Browse$ = _CWD$ + sel$ + arr(posx) + dd$: EXIT FUNCTION 'or if your choice is array record number then return PosX and erase $ in func name 'directory move is solved in my loop
            CASE 27: Browse$ = "---E": EXIT FUNCTION
        END SELECT
        IF posx <= 0 THEN posx = 0: Lb = 0
        IF posx > UBOUND(arr) - 1 THEN posx = UBOUND(arr) - 1
        IF oldposx <> posx THEN
            IF posx > height AND GD THEN Lb = Lb + 1: Le = Le + 1
            IF GU AND Lb > 0 THEN Lb = Lb - 1: Le = Le - 1

            textpos = 0
            IF Le > UBOUND(arr) THEN Le = UBOUND(arr)
            IF Le - Lb > height THEN Le = Lb + height
            FOR V = Lb TO Le 'List Begin to List End
                textpos = textpos + 20 'row is 20 pixel height
                IF V = posx THEN
                    COLOR InPosColor&, ListColor&
                ELSE
                    IF V > numDirs - 1 THEN COLOR ListColor& ELSE COLOR DirColor&
                    IF posx <= numDirs - 1 THEN dd$ = ".DIR." ELSE dd$ = ""
                END IF

                text$ = arr(V)
                IF LEN(text$) > lenght THEN text$ = LEFT$(text$, lenght - 3) + "..." ELSE text$ = text$ + SPACE$(lenght - LEN(text$))
                _PRINTSTRING (X, textpos), text$
                COLOR ListColor&, _RGB32(0, 0, 0)
            NEXT V

        END IF
    LOOP
END FUNCTION

SUB GetFileList (SearchDirectory AS STRING, DirList() AS STRING, FileList() AS STRING)
    CONST IS_DIR = 1
    CONST IS_FILE = 2
    DIM flags AS LONG, file_size AS LONG

    REDIM _PRESERVE DirList(100), FileList(100)
    DirCount = 0: FileCount = 0

    IF load_dir(SearchDirectory) THEN
        DO
            length = has_next_entry
            IF length > -1 THEN
                nam$ = SPACE$(length)
                get_next_entry nam$, flags, file_size
                IF flags AND IS_DIR THEN
                    DirCount = DirCount + 1
                    IF DirCount > UBOUND(DirList) THEN REDIM _PRESERVE DirList(UBOUND(DirList) + 100)
                    DirList(DirCount) = nam$
                ELSEIF flags AND IS_FILE THEN
                    FileCount = FileCount + 1
                    IF FileCount > UBOUND(filelist) THEN REDIM _PRESERVE FileList(UBOUND(filelist) + 100)
                    FileList(FileCount) = nam$
                END IF
            END IF
        LOOP UNTIL length = -1
        close_dir
    ELSE
    END IF
    REDIM _PRESERVE DirList(DirCount)
    REDIM _PRESERVE FileList(FileCount)
END SUB

Offline SMcNeill

  • QB64 Developer
Re: Browsing Directories / files using Steve´s library
« Reply #1 on: July 08, 2018, 11:13:53 AM »
Petr:  There is a way to get both folder information (which drives are available), and disk names, for both windows and Linux....   Problem is, I don't remember how I did it, right off the top of my head.  If you have a copy of my IDE which I was playing around with creating (StevesIDE), or my full fledged File Selection Utility (which I basically stripped from my IDE after working on it), then you can look inside either of them and see how I did it in the past.

If you don't have a copy of my IDE or FSU to examine, I'll dig up a version in a few days and refresh my memory on how I got all those things to work cross-platform.  I'd do it today for you, except my PC is in the shop having several internal fans and the power supply replaced.  I used to do such type repairs at home, but as I get old and my arthritis gets to hurting more, I find it simply easier and less stressful to leave such things to others anymore.

Give me 3-4 days to get my PC back, and if nobody has worked out a way by then, I'll dig out those old programs and see how I did it in the past again, for you.  ;)

Offline Petr

  • I am instructed.
Re: Browsing Directories / files using Steve´s library
« Reply #2 on: July 08, 2018, 11:34:31 AM »
Hi Steve, I'll look, but I do not have your files for 90 percent. It's a coincidence of coincidences, I'll just be for  daughter , now i waiting for a motherboard with processor and memory. About 3 months ago? I also left out the hard disk - he failure total,  so I got to know the UDF format I did not need before.  In old Computer my daughter ls wrong motherboard, there is a possibility of repair (it can be put into the oven and the temperature is kept under control for five minutes), it's due to lead-free tin, but ... I'd rather give her a new one.

Here I add the corrected previous program - I removed the sudden black death of the program. In the evening, I suppose I might be able to test it through Linux.

Code: [Select]
'files/directories list using Steve library (u.s. chars only)
'CHDIR "x:" tested on network drive, ok work correctly


DECLARE CUSTOMTYPE LIBRARY ".\direntry"
    FUNCTION load_dir& (s AS STRING)
    FUNCTION has_next_entry& ()
    SUB close_dir ()
    SUB get_next_entry (s AS STRING, flags AS LONG, file_size AS LONG)
END DECLARE
SCREEN _NEWIMAGE(800, 600, 32)


start:


REDIM Dir(0) AS STRING, File(0) AS STRING

IF LEN(runit$) THEN GetFileList runit$, Dir(), File() ELSE GetFileList _CWD$, Dir(), File()
REDIM All(UBOUND(dir) - 1 + UBOUND(file)) AS STRING

i = 0


FOR AllLoader = LBOUND(dir) + 2 TO UBOUND(dir) '                     i need not "." in list
    IF LEN(Dir(AllLoader)) THEN All(i) = Dir(AllLoader): i = i + 1
NEXT
FOR AllLoader = LBOUND(file) TO UBOUND(file)
    IF LEN(File(AllLoader)) THEN All(i) = File(AllLoader): i = i + 1
NEXT




DIRcount = UBOUND(dir) - 1
FILEcount = UBOUND(file)
IF DIRcount < 0 THEN DIRcount = 0

DO
    CLS
    runit$ = Browse$(All(), 10, 10, 70, 15, DIRcount) 'array  contains files/directories names, this list X start coordinate, this list Y start coordinate, This list lenght (300 pixel lenght), 30 records in this list to view), return file/folder/"..", "." name which is selected
    IF runit$ = "---E" THEN END
    IF runit$ = "" THEN GOTO start
    IF RIGHT$(runit$, 5) = ".DIR." THEN
        runit$ = LEFT$(runit$, LEN(runit$) - 5)
        CLS
        REM    PRINT runit$: SLEEP
        CHDIR runit$: GOTO start
    END IF
    IF RIGHT$(runit$, 2) = ".." THEN CHDIR "..": GOTO start
    IF LEN(runit$) THEN SHELL _DONTWAIT runit$

LOOP



FUNCTION Browse$ (arr() AS STRING, X, Y, lenght, height, numDirs)
    fail:
    ListColor& = _RGB32(166, 244, 244)
    InPosColor& = _RGB32(67, 72, 238)
    DirColor& = _RGB32(238, 22, 28)
    Lb = 1
    Le = 20
    IF INSTR(1, _OS$, "WINDOWS") THEN sel$ = CHR$(92)
    IF INSTR(1, _OS$, "LINUX") THEN sel$ = "/"
    First = 1
    DO
        K& = _KEYHIT
        oldposx = posx
        IF First THEN oldposx = -1: First = 0
        SELECT CASE K&
            CASE 18432: posx = posx - 1: GU = 1: GD = 0 'marks: Go down disabled, go up enbabled
            CASE 20480: posx = posx + 1: GU = 0: GD = 1 'marks: Go down enabled, go up disabled
            CASE 13: Browse$ = _CWD$ + sel$ + arr(posx) + dd$: EXIT FUNCTION 'or if your choice is array record number then return PosX and erase $ in func name 'directory move is solved in my loop
            CASE 27: Browse$ = "---E": EXIT FUNCTION
        END SELECT
        IF posx <= 0 THEN posx = 0: Lb = 0
        '        IF arr(posx) = "." THEN posx = 1: Lb = 1

        IF posx > UBOUND(arr) - 1 THEN posx = UBOUND(arr) - 1
        IF oldposx <> posx THEN
            IF posx > height AND GD THEN Lb = Lb + 1: Le = Le + 1
            IF GU AND Lb > 0 THEN Lb = Lb - 1: Le = Le - 1

            textpos = 0
            IF Le > UBOUND(arr) THEN Le = UBOUND(arr)
            IF Le - Lb > height THEN Le = Lb + height
            IF Lb > Le THEN EXIT SUB
            FOR V = Lb TO Le 'List Begin to List End
                textpos = textpos + 20 'row is 20 pixel height
                IF V = posx THEN
                    COLOR InPosColor&, ListColor&
                ELSE
                    IF V > numDirs - 1 THEN COLOR ListColor& ELSE COLOR DirColor&
                    IF posx <= numDirs - 1 THEN dd$ = ".DIR." ELSE dd$ = ""
                END IF

                text$ = arr(V)
                IF LEN(text$) > lenght THEN text$ = LEFT$(text$, lenght - 3) + "..." ELSE text$ = text$ + SPACE$(lenght - LEN(text$))
                _PRINTSTRING (X, textpos), text$
                COLOR ListColor&, _RGB32(0, 0, 0)
            NEXT V
        END IF
        _LIMIT 25
    LOOP
END FUNCTION

SUB GetFileList (SearchDirectory AS STRING, DirList() AS STRING, FileList() AS STRING)
    CONST IS_DIR = 1
    CONST IS_FILE = 2
    DIM flags AS LONG, file_size AS LONG

    REDIM _PRESERVE DirList(100), FileList(100)
    DirCount = 0: FileCount = 0

    IF load_dir(SearchDirectory) THEN
        DO
            length = has_next_entry
            IF length > -1 THEN
                nam$ = SPACE$(length)
                get_next_entry nam$, flags, file_size
                IF flags AND IS_DIR THEN
                    DirCount = DirCount + 1
                    IF DirCount > UBOUND(DirList) THEN REDIM _PRESERVE DirList(UBOUND(DirList) + 100)
                    DirList(DirCount) = nam$
                ELSEIF flags AND IS_FILE THEN
                    FileCount = FileCount + 1
                    IF FileCount > UBOUND(filelist) THEN REDIM _PRESERVE FileList(UBOUND(filelist) + 100)
                    FileList(FileCount) = nam$
                END IF
            END IF
        LOOP UNTIL length = -1
        close_dir
    ELSE
    END IF
    REDIM _PRESERVE DirList(DirCount)
    REDIM _PRESERVE FileList(FileCount)
END SUB


Offline SMcNeill

  • QB64 Developer
Re: Browsing Directories / files using Steve´s library
« Reply #3 on: July 08, 2018, 08:07:18 PM »
See if this is what you're looking for Petr:

Code: [Select]
DECLARE CUSTOMTYPE LIBRARY ".\direntry"
    FUNCTION FILE_load_dir& ALIAS load_dir (s AS STRING)
    FUNCTION FILE_has_next_entry& ALIAS has_next_entry ()
    SUB FILE_close_dir ALIAS close_dir ()
    SUB FILE_get_next_entry ALIAS get_next_entry (s AS STRING, flags AS LONG, file_size AS LONG)
    SUB FILE_get_current_dir ALIAS get_current_dir (s AS STRING)
    FUNCTION FILE_current_dir_length& ALIAS current_dir_length ()
END DECLARE


_DEFINE A-Z AS LONG
SCREEN _NEWIMAGE(800, 600, 32)
f$ = SelectFile$("*.BI;*.BAS;*.BM;*.*", 60, 60)
PRINT "You picked "; f$




FUNCTION SelectFile$ (search$, x AS INTEGER, y AS INTEGER)
    'save some old values
    LoadFile_DC = _DEFAULTCOLOR: LoadFile_BG = _BACKGROUNDCOLOR
    LoadFile_s = _SOURCE: LoadFile_d = _DEST
    f = _FONT: _FONT 16
    'some variables

    LoadFile_BoxColor = &HFFAAAAFF
    LoadFile_FolderColor = &HFFFFFF00
    LoadFile_FileColor = &HFFFFFFFF
    IF INSTR(_OS$, "[WINDOWS]") THEN LoadFile_Slash$ = "\" ELSE LoadFile_Slash$ = "/"
    LoadFile_Dir$ = SPACE$(FILE_current_dir_length)
    FILE_get_current_dir LoadFile_Dir$
    LoadFile_Dir$ = LoadFile_Dir$ + LoadFile_Slash$
    LoadFile_w = 639: LoadFile_h = 479
    REDIM LoadFile_Label(0) AS STRING: LoadFile_Label(0) = "DIR"
    REDIM LoadFile_DirList(-1 TO 9, -1 TO 9999) AS STRING
    LoadFile_last = 1
    REDIM Drives(0) AS STRING

    'some error checking
    IF search$ = "" THEN EXIT SUB 'We can't search for nothing!

    'Copy background
    PCOPY 0, 1
    'set workscreen
    LoadFile_ws = _NEWIMAGE(640, 480, 32)

    'Count our filetypes to display
    LoadFile_TypeCount = 0
    DO
        LoadFile_TypeCount = LoadFile_TypeCount + 1
        LoadFile_l = INSTR(LoadFile_l + 1, search$, ";") ' look for ; to denote more files
        REDIM _PRESERVE LoadFile_Label(LoadFile_TypeCount) AS STRING
        IF LoadFile_l > 0 THEN LoadFile_Label(LoadFile_TypeCount) = MID$(search$, LoadFile_last + 1, LoadFile_l - LoadFile_last - 1) ELSE LoadFile_Label(LoadFile_TypeCount) = MID$(search$, LoadFile_last + 1, LEN(search$) - LoadFile_last)
        LoadFile_last = LoadFile_l + 1
    LOOP UNTIL LoadFile_l = 0
    LoadFile_l = 640 / (LoadFile_TypeCount + 1)
    REDIM LoadFile_start(LoadFile_TypeCount), LoadFile_previous(LoadFile_TypeCount), LoadFile_more(LoadFile_TypeCount), LoadFile_Count(LoadFile_TypeCount)
    FOR i = 0 TO LoadFile_TypeCount: LoadFile_start(i) = 1: NEXT

    'Get the windows drive letters
    IF INSTR(_OS$, "[WINDOWS]") THEN
        SHELL _HIDE CHR$(34) + "wmic logicaldisk get name" + CHR$(34) + ">TempDirList.txt"
        REDIM Drives(0) AS STRING

        OPEN "TempDirList.txt" FOR INPUT AS #1
        LINE INPUT #1, junk$ 'First line is  name
        counter = 0
        DO UNTIL EOF(1)
            counter = counter + 1
            INPUT #1, junk$ 'drive name
            REDIM _PRESERVE Drives(counter) AS STRING
            IF LEN(junk$) > 1 THEN junk$ = MID$(junk$, 2, 1) + ":" ELSE junk$ = "": counter = counter - 1
            IF junk$ <> "" THEN
                Drives(counter) = junk$
            END IF
        LOOP
        CLOSE #1
        KILL "TempDirList.txt"
    END IF


    _SOURCE LoadFile_ws: _DEST LoadFile_ws
    DO

        FOR i = 0 TO LoadFile_TypeCount
            LoadFile_Count(i) = 0
            FOR j = 0 TO 9999
                LoadFile_DirList(i, j) = ""
            NEXT
        NEXT
        'Generate our updated directory listings.

        IF FILE_load_dir&(LoadFile_Dir$ + CHR$(0)) THEN
            DO
                LoadFile_length = FILE_has_next_entry 'Get length of next entry
                IF LoadFile_length > -1 THEN 'If we have a next entry
                    LoadFile_nam$ = SPACE$(LoadFile_length) 'Set the size of our string
                    FILE_get_next_entry LoadFile_nam$, LoadFile_flags, LoadFile_file_size 'Get the file's name, size, and 'flags'
                    'Check if it's a file or a directory

                    IF _DIREXISTS(LoadFile_Dir$ + LoadFile_nam$) THEN
                        IF LoadFile_nam$ <> "." THEN
                            LoadFile_Count(0) = LoadFile_Count(0) + 1
                            LoadFile_DirList(0, LoadFile_Count(0)) = LoadFile_nam$
                        END IF
                    ELSE 'We have a file
                        FOR i = 1 TO LoadFile_TypeCount
                            LoadFile_ext$ = RIGHT$(LoadFile_nam$, LEN(LoadFile_Label(i)))
                            IF UCASE$(LoadFile_ext$) = UCASE$(LoadFile_Label(i)) THEN
                                LoadFile_Count(i) = LoadFile_Count(i) + 1
                                LoadFile_DirList(i, LoadFile_Count(i)) = LEFT$(LoadFile_nam$, LEN(LoadFile_nam$) - LEN(LoadFile_Label(i)))
                                EXIT FOR
                            ELSEIF LoadFile_Label(i) = ".*" THEN
                                LoadFile_Count(i) = LoadFile_Count(i) + 1
                                LoadFile_DirList(i, LoadFile_Count(i)) = LoadFile_nam$
                            END IF
                        NEXT
                    END IF
                END IF
            LOOP UNTIL LoadFile_length = -1
            FILE_close_dir
        END IF

        FOR i = 1 TO UBOUND(drives)
            LoadFile_Count(0) = LoadFile_Count(0) + 1
            LoadFile_DirList(0, LoadFile_Count(0)) = Drives(i)
        NEXT

        updatelist:

        CLS , &HFF005050 'Draw a nice display box
        COLOR , 0
        LINE (0, 0)-(LoadFile_w, LoadFile_h + 5 - 2 * 16), LoadFile_BoxColor, B
        LINE (1, 1)-(LoadFile_w - 1, LoadFile_h + 6 - 2 * 16), LoadFile_BoxColor, B
        LINE (0, 0)-(LoadFile_w, LoadFile_h), LoadFile_BoxColor, B
        LINE (1, 1)-(LoadFile_w - 1, LoadFile_h - 1), LoadFile_BoxColor, B

        LINE (0, 16 + 3)-(LoadFile_w, 16 + 3), LoadFile_BoxColor
        LINE (0, 16 + 4)-(LoadFile_w, 16 + 4), LoadFile_BoxColor
        FOR i = 0 TO LoadFile_TypeCount
            _PRINTSTRING (i * LoadFile_l + (LoadFile_l - 8 * LEN(LoadFile_Label(i))) / 2, 2), LoadFile_Label(i)
            LINE (i * LoadFile_l, 0)-(i * LoadFile_l, LoadFile_h + 5 - 2 * 16), LoadFile_BoxColor
        NEXT

        LINE (627, 2)-(637, 18), &HFFFF0000, BF
        LINE (626, 2)-(637, 18), &HFF000000, B

        _PRINTSTRING (628, 2), "X"
        IF selection > 0 THEN
            IF LoadFile_Label(row) <> ".*" AND LoadFile_Label(row) <> "DIR" THEN temp$ = LoadFile_DirList(row, selection) + LoadFile_Label(row) ELSE temp$ = LoadFile_DirList(row, selection)
            IF LoadFile_DirList(row, selection) = "" THEN temp$ = ""
            selection = 0
        END IF
        _PRINTSTRING (10, 28 * 16 + 7), LoadFile_Dir$
        _PRINTSTRING (630 - LEN(temp$) * 8, 28 * 16 + 7), temp$
        IF temp$ = "" THEN oldselection = 0
        IF oldselection > 0 THEN LINE (row * LoadFile_l, (oldselection + 1) * 16 + 5)-((row + 1) * LoadFile_l, (oldselection + 2) * 16 + 5), &HAAAAA000, BF

        FOR i = 0 TO UBOUND(LoadFile_label)
            IF i = 0 THEN COLOR LoadFile_FolderColor ELSE COLOR LoadFile_FileColor
            counter = 0
            FOR j = LoadFile_start(i) TO LoadFile_start(i) + 24
                counter = counter + 1
                IF LoadFile_DirList(i, j) = "" THEN EXIT FOR
                _PRINTSTRING (i * LoadFile_l + 5, (counter + 1) * 16 + 7), LEFT$(LoadFile_DirList(i, j), LoadFile_l / 8 - 2)
            NEXT
            IF j = LoadFile_start(i) + 25 THEN LoadFile_more(i) = -1 ELSE LoadFile_more(i) = 0
            IF LoadFile_start(i) > 1 THEN LoadFile_previous(i) = -1 ELSE LoadFile_previous(i) = 0
            IF LoadFile_more(i) THEN
                LINE (i * LoadFile_l + 2, 27 * 16 + 5)-((i + 1) * LoadFile_l - 3, 28 * 16 + 3), &HFFFF0000, BF
                LINE (i * LoadFile_l + 2, 27 * 16 + 5)-((i + 1) * LoadFile_l - 3, 28 * 16 + 3), BoxColor, B
                COLOR &HFFFFFF00: _PRINTSTRING (i * LoadFile_l + (LoadFile_l - 8 * 11) / 2, 27 * 16 + 5), "SCROLL DOWN"
                COLOR LoadFile_FileColor
            END IF
            IF LoadFile_previous(i) THEN
                LINE (i * LoadFile_l + 2, 16 + 5)-((i + 1) * LoadFile_l - 3, 2 * 16 + 3), &HFFFF0000, BF
                LINE (i * LoadFile_l + 2, 16 + 5)-((i + 1) * LoadFile_l - 3, 2 * 16 + 3), BoxColor, B
                COLOR &HFFFFFF00: _PRINTSTRING (i * LoadFile_l + (LoadFile_l - 8 * 9) / 2, 16 + 5), "SCROLL UP"
                COLOR LoadFile_FileColor
            END IF
        NEXT

        _PUTIMAGE (0 + x, 0 + y)-(640 + x, 480 + y), LoadFile_ws, 0
        _DISPLAY

        change = 0
        DO
            _DELAY .05
            LoadFile_LMB = 0 'This sets the left mouse button as unacceptable.
            a = _KEYHIT
            SELECT CASE a
                CASE 8 'backspace
                    temp$ = LEFT$(temp$, LEN(temp$) - 1)
                    change = -1
                CASE 13 'enter
                    DO: LOOP UNTIL INKEY$ = "" 'Clear the keyboard buffer so it doesn't affect the main program.
                    temp$ = LoadFile_Dir$ + temp$
                    COLOR LoadFile_DC, LoadFile_BG: _SOURCE LoadFile_s: _DEST LoadFile_d: PCOPY 1, 0: _DISPLAY: SelectFile$ = temp$ 'Restore our old settings
                    _FONT f
                    EXIT SUB 'And leave
                CASE 27 'If ESC is pressed then...
                    DO: LOOP UNTIL INKEY$ = "" 'Clear the keyboard buffer so it doesn't affect the main program.
                    COLOR LoadFile_DC, LoadFile_BG: _SOURCE LoadFile_s: _DEST LoadFile_d: PCOPY 1, 0: _DISPLAY: SelectFile$ = "" 'Restore our old settings
                    _FONT f
                    EXIT SUB 'And leave
                CASE 32 TO 126
                    temp$ = temp$ + CHR$(a)
                    change = -1
            END SELECT
            DO
                MS = MS + _MOUSEWHEEL
                IF _MOUSEBUTTON(1) = 0 THEN LoadFile_LMB = -1 'Only by lifting the mouse, will we count it as down
                'Note: we ignore LoadFile_LMB for the scroll bars, so we can just hold it down and scroll happily forever and ever...
                'or until we get to the limit of our file list.
                'We only check LoadFile_LMB when actually trying to select an item from our list.   No more "OOP!  I held it too long and did something I didn't want to do!"
                'Now we click once to select, click again to accept that selection.
            LOOP WHILE _MOUSEINPUT
            MX = _MOUSEX: MY = _MOUSEY
            IF _MOUSEBUTTON(2) OR (LoadFile_LMB AND MX > 626 + x AND MX < 638 + x AND MY > 1 + y AND MY < 19 + y AND _MOUSEBUTTON(1)) THEN
                'restore those old values, and just exit.  Right mouse is an escape
                COLOR LoadFile_DC, LoadFile_BG: _SOURCE LoadFile_s: _DEST LoadFile_d: PCOPY 1, 0: _DISPLAY: SelectFile$ = ""
                _FONT f
                EXIT SUB
            END IF





            IF _MOUSEBUTTON(1) THEN 'Without the mouse being down, we don't need to check squat!
                'Check the 2 roLoadFile_ws for a click in the proper Y position
                IF MY >= 16 + 5 + y AND MY <= 2 * 16 + 3 + y THEN 'We're on the top row
                    FOR j = 0 TO UBOUND(LoadFile_label)
                        IF LoadFile_previous(j) AND MX >= j * LoadFile_l + 2 + x AND MX <= (j + 1) * LoadFile_l - 3 + x THEN
                            LoadFile_start(j) = LoadFile_start(j) - 1
                            change = -1: selection = 0: click = 0: temp$ = ""
                            EXIT FOR
                        END IF
                    NEXT
                ELSEIF MY >= 27 * 16 + 5 + y AND MY <= 28 * 16 + 3 + y THEN 'We're on the bottom row
                    FOR j = 0 TO UBOUND(LoadFile_label)
                        IF LoadFile_more(j) AND MX >= j * LoadFile_l + 2 + x AND MX <= (j + 1) * LoadFile_l - 3 + x THEN
                            LoadFile_start(j) = LoadFile_start(j) + 1
                            change = -1: selection = 0: click = 0: temp$ = ""
                            EXIT FOR
                        END IF
                    NEXT
                ELSEIF MY >= 37 + y AND MY <= 437 + y AND LoadFile_LMB THEN 'It's in a column somewhere.  Did someone click an item?!
                    FOR j = 0 TO UBOUND(LoadFile_label)
                        IF MX >= j * LoadFile_l + 2 + x AND MX <= (j + 1) * LoadFile_l - 3 + x THEN
                            row = j
                            oldselection = INT((MY - y - 37) / 16) + 1
                            selection = LoadFile_start(j) + oldselection - 1
                            change = -1
                            click = -1
                            EXIT FOR
                        END IF
                    NEXT
                END IF
            END IF
            IF MS <> 0 THEN
                IF MY >= 37 + y AND MY <= 437 + y AND LoadFile_LMB THEN 'It's in a column somewhere.  Did someone click an item?!
                    FOR j = 0 TO UBOUND(LoadFile_label)
                        IF MX >= j * LoadFile_l + 2 + x AND MX <= (j + 1) * LoadFile_l - 3 + x THEN
                            IF LoadFile_previous(j) AND MS < 1 THEN
                                LoadFile_start(j) = LoadFile_start(j) - 5
                                IF LoadFile_start(j) < 1 THEN LoadFile_start(j) = 1
                                change = -1: selection = 0: click = 0: temp$ = ""
                                MS = 0
                            ELSEIF LoadFile_more(j) AND MS > 1 THEN
                                LoadFile_start(j) = LoadFile_start(j) + 5
                                change = -1: selection = 0: click = 0: temp$ = ""
                                MS = 0
                            END IF
                            EXIT FOR
                        END IF
                    NEXT
                ELSE MS = 0
                END IF
            END IF
            _DISPLAY
        LOOP UNTIL change
        IF click THEN 'we clicked something besides a scroll bar
            IF LoadFile_Label(row) <> ".*" AND LoadFile_Label(row) <> "DIR" THEN temp1$ = LoadFile_DirList(row, selection) + LoadFile_Label(row) ELSE temp1$ = LoadFile_DirList(row, selection)
            IF temp$ = temp1$ THEN
                'We picked one!
                SELECT CASE LoadFile_Label(row)
                    CASE "DIR"
                        SELECT CASE LoadFile_DirList(row, selection)
                            CASE "" 'Do nothing with blank directories
                            CASE ".." 'Up a folder
                                DO
                                    LoadFile_Dir$ = LEFT$(LoadFile_Dir$, LEN(LoadFile_Dir$) - 1)
                                LOOP UNTIL RIGHT$(LoadFile_Dir$, 1) = LoadFile_Slash$ OR LEN(LoadFile_Dir$) = 0
                            CASE ELSE 'To a specific folder
                                IF LEN(LoadFile_DirList(row, selection)) = 2 AND RIGHT$(LoadFile_DirList(row, selection), 1) = ":" THEN
                                    'It's a directory change
                                    LoadFile_Dir$ = LoadFile_DirList(row, selection) + LoadFile_Slash$
                                ELSE
                                    LoadFile_Dir$ = LoadFile_Dir$ + LoadFile_DirList(row, selection) + LoadFile_Slash$
                                END IF
                        END SELECT
                        FOR i = 0 TO UBOUND(Loadfile_start)
                            LoadFile_start(i) = 1
                        NEXT
                        selection = 0: temp$ = "": oldselection = 0
                    CASE ".*": SelectFile$ = LoadFile_Dir$ + temp$: EXIT DO
                    CASE ELSE: SelectFile$ = LoadFile_Dir$ + temp$: EXIT DO
                END SELECT
            END IF
            IF row > 0 THEN _DELAY .2: GOTO updatelist
        ELSE
            _DELAY .05
            GOTO updatelist
        END IF
    LOOP
    'restore those old values
    COLOR LoadFile_DC, LoadFile_BG: _SOURCE LoadFile_s: _DEST LoadFile_d: PCOPY 1, 0: _DISPLAY
    _FONT f
END SUB

'If you don't have a copy of direntry.h in your QB64 folder, then copy the following code into a new IDE window.
'Then remove the remarks.
'And save it as direntry.h
'direntry.h is required for this to work properly with the library files.
'I thought adding the code here would be a way to make certain that it'd be easy to recover the file
'in case something ever happened and it was accidently deleted off the drive for some reason.

'#include <dirent.h>
'#include <sys/stat.h>
'#include <unistd.h>

'const int IS_DIR_FLAG = 1, IS_FILE_FLAG = 2;

'DIR *pdir;
'struct dirent *next_entry;
'struct stat statbuf1;

'char current_dir[FILENAME_MAX];
'#ifdef QB64_WINDOWS
'  #define GetCurrentDir _getcwd
'#else
'  #define GetCurrentDir getcwd
'#endif

'int load_dir (char * path) {
'  struct dirent *pent;
'  struct stat statbuf1;
'//Open current directory
'pdir = opendir(path);
'if (!pdir) {
'return 0; //Didn't open
'}
'return -1;
'}

'int has_next_entry () {
'  next_entry = readdir(pdir);
'  if (next_entry == NULL) return -1;

'  stat(next_entry->d_name, &statbuf1);
'  return strlen(next_entry->d_name);
'}

'void get_next_entry (char * nam, int * flags, int * file_size) {
'  strcpy(nam, next_entry->d_name);
'  if (S_ISDIR(statbuf1.st_mode)) {
'    *flags = IS_DIR_FLAG;
'  } else {
'    *flags = IS_FILE_FLAG;
'  }
'  *file_size = statbuf1.st_size;
'  return ;
'}

'void close_dir () {
'  closedir(pdir);
'  pdir = NULL;
'  return ;
'}

'int current_dir_length () {
'  GetCurrentDir(current_dir, sizeof(current_dir));
'  return strlen(current_dir);
'}

'void get_current_dir(char *dir) {
'  memcpy(dir, current_dir, strlen(current_dir));
'  return ;
'}

Just be certain to have the direntry.h file where it can be found, and you should be good to go.

Offline Petr

  • I am instructed.
Re: Browsing Directories / files using Steve´s library
« Reply #4 on: July 09, 2018, 11:54:32 AM »
Hi Steve. Yes, it is, thank you. Does the disk listing appear to be only for windows? (I will study the linux commands sequentially if there is not the same option). Thank you very much for your idea and source!

Offline SMcNeill

  • QB64 Developer
Re: Browsing Directories / files using Steve´s library
« Reply #5 on: July 09, 2018, 03:25:39 PM »
Hi Steve. Yes, it is, thank you. Does the disk listing appear to be only for windows? (I will study the linux commands sequentially if there is not the same option). Thank you very much for your idea and source!

Linux and Windows are inherently different in the way they handle their file system.  Take a quick read here:  https://www.howtogeek.com/137096/6-ways-the-linux-file-system-is-different-from-the-windows-file-system/

The particular point of interest for you, in this case, would be:

No Drive Letters – It’s All Under /

Windows exposes partitions and devices at drive letters. Whether you have multiple hard drives, multiple partitions on the same hard drive, or removable devices connected, each file system is available under its own drive letter.

Linux doesn’t have drive letters. Instead, it makes other file systems accessible at arbitrary directories. (Windows can do this too, but this isn’t how it works out of the box.)

On Linux, everything is under / – the root directory. There are no files above the root directory, as there are files outside of C: on Windows. When you connect a device to your computer, it will become available under /media/. The contents of the directory display the contents of the mounted partition.

Offline Petr

  • I am instructed.
Re: Browsing Directories / files using Steve´s library
« Reply #6 on: July 09, 2018, 05:11:44 PM »
Thank you for the explanation. After several attempts (DVD ROM after death,too small FlashDisc, fragmented harddrive....), I finally i got to computer Linux Mint. I will experimented.

Re: Browsing Directories / files using Steve´s library
« Reply #7 on: July 10, 2018, 12:16:54 PM »
Wow, amazing work Petr and Steve. I think these dir listing routines along with Steve's circle fill are the two most prolific code snippets in QB64. Really speaks for Steve's immensity.

Offline Petr

  • I am instructed.
Re: Browsing Directories / files using Steve´s library
« Reply #8 on: July 10, 2018, 01:41:42 PM »
Thank you, V, I'm still improving function Browse$.

Offline Petr

  • I am instructed.
Re: Browsing Directories / files using Steve´s library
« Reply #9 on: August 13, 2018, 05:54:48 PM »
This is my latest version, so far it does not support GOOD mouse drives switching (support files / directories move by clicking to arrow ) but can be switched by keyboard (just press character). I still need to make an alphabetical order for linux. Here I have a problem. What should be first. Small or big character? I did not try it in Linux, I'm a little while after vacation. In the windows, I've been having problems with links that have returned as directories or directories that are not directly accessible. I will use this program for Sprite editor, which I promised Johnno56.


Code: [Select]
'files/directories list using Steve library (u.s. chars only)
'CHDIR "x:" tested on network drive, ok work correctly

REDIM Drives(0) AS STRING
DECLARE CUSTOMTYPE LIBRARY ".\direntry"
    FUNCTION load_dir& (s AS STRING)
    FUNCTION has_next_entry& ()
    SUB close_dir ()
    SUB get_next_entry (s AS STRING, flags AS LONG, file_size AS LONG)
END DECLARE

SCREEN _NEWIMAGE(800, 600, 32)


Drives$ = LoadDrives$(Drives()) 'windows only in current version


REDIM DirNew(0) AS STRING
REDIM FileNew(0) AS STRING

start:


REDIM Dir(0) AS STRING, File(0) AS STRING


GetFileList _CWD$, Dir(), File()
REDIM All(UBOUND(dir) - 1 + UBOUND(file)) AS STRING

i = 0


FOR AllLoader = LBOUND(dir) + 2 TO UBOUND(dir) '                     i need not "." in list
    IF LEN(Dir(AllLoader)) THEN All(i) = Dir(AllLoader): i = i + 1
NEXT
FOR AllLoader = LBOUND(File) TO UBOUND(File)
    IF LEN(File(AllLoader)) THEN All(i) = File(AllLoader): i = i + 1
NEXT

IF UBOUND(all) <= 0 THEN CHDIR (LEFT$(_CWD$, 3)): GOTO start

DIRcount = UBOUND(dir) - 1
FILEcount = UBOUND(File)
IF DIRcount < 0 THEN DIRcount = 0
IF INSTR(1, _OS$, "WINDOWS") THEN OS = 0
IF INSTR(1, _OS$, "LINUX") THEN OS = 1

DO
    CLS
    runit$ = ""
    runit$ = Browse$(All(), 20, 15, 40, 9, DIRcount, Drives$, 1) 'array  contains files/directories names, this list X start coordinate, this list Y start coordinate, This list lenght (300 pixel lenght), 30 records in this list to view), return file/folder/"..", "." name which is selected. Last parameter is for DRIVE characters (names) STRING
    '    PRINT runit$: SLEEP 2
    ON ERROR GOTO handler


    SELECT CASE OS
        CASE 0
            invalid = INSTR(1, runit$, "\\")
        CASE 1
            invalid = INSTR(1, runit$, "//")
    END SELECT
    IF invalid THEN runit$ = LEFT$(runit$, invalid) + RIGHT$(runit$, LEN(runit$) - invalid - 1)


    IF RIGHT$(runit$, 1) = "." AND OS = 1 THEN BEEP: CHDIR "/": _DELAY .1: GOTO start



    IF runit$ = "---E" THEN END
    IF runit$ = "" THEN CHDIR LEFT$(_CWD$, 3): _DELAY .1: GOTO start
    IF RIGHT$(runit$, 2) = ".." AND _DIREXISTS("..") THEN CHDIR "..": _DELAY .1: GOTO start
    IF RIGHT$(runit$, 5) = ".DIR." THEN
        runit$ = LEFT$(runit$, LEN(runit$) - 5)
        CHDIR runit$
        _DELAY .1
        GOTO start
    END IF

    IF LEN(runit$) AND _FILEEXISTS(runit$) THEN SHELL _DONTWAIT runit$
LOOP


handler:

PRINT "error handler RUN!!!!": SLEEP 2
SELECT CASE ERR
    CASE 76: CHDIR LEFT$(_CWD$, 3) + ":": GOTO start: RESUME NEXT 'path not found ugrade / add + ":" and goto start
END SELECT



FUNCTION Browse$ (arr() AS STRING, X, Y, lenght, height, numDirs, Drives AS STRING, UseWheel)
    ' X and Y are coordinates for left upper corner, lenght is window lenght in CHARACTERS, height is window height in records + 2, numDirs = how nmuch
    ' records from begin in array arr() are DIRECTORIES, Drives is string contains valid disk names in Windows, in Linux it is empty string

    ListColor& = _RGB32(166, 244, 244)
    InPosColor& = _RGB32(67, 72, 238)
    DirColor& = _RGB32(238, 22, 28)
    'create string with drives names (i see this first by Eoredson)
    FOR Driv = 1 TO LEN(Drives)
        OnScreenDrives$ = OnScreenDrives$ + "[" + MID$(Drives$, Driv, 1) + ":] "
    NEXT Driv
    IF LEN(OnScreenDrives$) > lenght THEN OnScreenDrives$ = LEFT$(OnScreenDrives$, lenght - 3) + LTRIM$("...")

    IF Lb = 0 AND le = 0 THEN
        Lb = 1
        le = 20
    END IF

    IF INSTR(1, _OS$, "WINDOWS") THEN sel$ = CHR$(92)
    IF INSTR(1, _OS$, "LINUX") THEN sel$ = "/"
    first = 1



    DO
        K& = _KEYHIT
        iink$ = UCASE$(INKEY$)
        IF LEN(iink$) THEN
            IF INSTR(1, Drives$, iink$) THEN
                newdrive$ = iink$ + ":": CHDIR newdrive$: EXIT FUNCTION
            END IF
            iink$ = ""
        END IF
        oldposx = posx
        IF first THEN oldposx = -1: first = 0


        'mouse support ---

        WHILE _MOUSEINPUT
            MoX = _MOUSEX: MoY = _MOUSEY
            IF MoX > X AND MoX < X + ((lenght + 4) * 8) AND MoY > Y AND MoY < Y + (height * 20) + 40 THEN 'podle LINE

                poloha = _CEIL((MoY - Y - 20) / 20) 'pro mys


                IF UseWheel THEN ' in function last parameter: 0 = use wheel, 1 = not use wheel
                    SELECT CASE SGN(_MOUSEWHEEL)
                        CASE -1: K& = 18432
                        CASE 1: K& = 20480
                    END SELECT

                ELSE


                    IF poloha < posx - Lb THEN K& = 18432
                    IF poloha > posx - Lb THEN K& = 20480
                END IF



                IF _MOUSEBUTTON(1) AND poloha >= Lb AND poloha <= le THEN
                    IF MoX < (8 * lenght) + X THEN K& = 13: _DELAY .1

                END IF



                IF _MOUSEBUTTON(1) AND MoX > (8 * lenght) + X AND MoY < Y + 16 THEN 'mouse / up arrow
                    K& = 18432
                END IF


                IF _MOUSEBUTTON(1) AND MoX > (8 * lenght) + X AND MoY > Y + (height * 20) + 24 THEN 'mouse / down arrow
                    K& = 20480
                END IF
            END IF

            'podpora prepnuti disku mysi: drive select mouse support (alfa - not full tested)

            IF MoX >= X + 10 AND MoX < X + 10 + (8 * LEN(OnScreenDrives$)) - 8 AND MoY >= (Y + 20 * height) + 50 AND MoY < (Y + 20 * height) + 66 THEN
                IF _MOUSEBUTTON(1) THEN
                    DiskSel = _CEIL(((MoX - X + 10) / 8) / 6)
                    IF DiskSel > LEN(Drives$) THEN DiskSel = LEN(DiskSel)
                    iink$ = MID$(Drives$, DiskSel, 1)
                    newdrive$ = iink$ + ":": CHDIR newdrive$: EXIT FUNCTION
                END IF
            END IF

        WEND
        '------------------


        ' --- keyboard inputs
        SELECT CASE K&
            CASE 18432: posx = posx - 1: GU = 1: GD = 0 'marks: Go down disabled, go up enbabled
            CASE 20480: posx = posx + 1: GU = 0: GD = 1 'marks: Go down enabled, go up disabled
            CASE 13: Browse$ = _CWD$ + sel$ + arr(posx) + dd$: EXIT FUNCTION 'or if your choice is array record number then return PosX and erase $ in func name 'directory move is solved in my loop
            CASE 27: Browse$ = "---E": EXIT FUNCTION
            CASE 32:
        END SELECT
        ' -------------------

        'if is link selected (not dir):
        IF UBOUND(arr) < 0 THEN EXIT FUNCTION 'Browse$ = LEFT$(_CWD$, 3): EXIT FUNCTION
        'end of bug repair

        IF posx <= 0 THEN posx = 0: Lb = 0: le = Lb + height
        IF posx > UBOUND(arr) - 1 THEN posx = UBOUND(arr) - 1
        IF oldposx <> posx THEN
            IF posx > le AND GD THEN Lb = Lb + 1: le = le + 1
            IF GU AND posx < Lb THEN Lb = Lb - 1: le = le - 1
            textpos = 0
            IF le > UBOUND(arr) THEN le = UBOUND(arr)
            IF le - Lb > height THEN le = Lb + height
            IF Lb > le THEN EXIT FUNCTION


            FOR V = Lb TO le 'List Begin to List End
                textpos = textpos + 20 'row is 20 pixel height
                IF V = posx THEN
                    COLOR InPosColor&, ListColor&
                ELSE
                    IF V > numDirs - 1 THEN COLOR ListColor& ELSE COLOR DirColor&
                    IF posx <= numDirs - 1 THEN dd$ = ".DIR." ELSE dd$ = ""
                END IF
                text$ = arr(V)
                IF LEN(text$) > lenght - 2 THEN text$ = LEFT$(text$, lenght - 4) + LTRIM$("...") ELSE text$ = text$ + SPACE$(lenght - LEN(text$) - 1)
                _PRINTSTRING (X + 10, Y + textpos), text$
                COLOR ListColor&, _RGB32(0, 0, 0)


                possss = posx + 1


                Posuvnik_V_Procentech! = (possss / UBOUND(arr))

                '----------------------------------------------------------------------- dodelat
                WindowHeight = (23 + height * 20) - 40
                OldGC = GC
                GC = Y + WindowHeight * Posuvnik_V_Procentech!

                COLOR _RGB32(0, 0, 0)
                _PRINTSTRING (X + 5 + lenght * _FONTWIDTH, OldGC + 22), CHR$(222)
                COLOR _RGB32(127, 127, 127)
                _PRINTSTRING (X + 5 + lenght * _FONTWIDTH, GC + 22), CHR$(222)

                _PRINTSTRING (X + 5 + lenght * _FONTWIDTH, Y + 7), CHR$(24)
                _PRINTSTRING (X + 5 + lenght * _FONTWIDTH, 3 + Y + 20 + height * 20), CHR$(25)
                '---------------------------------------------------------------------------

            NEXT V

            diskar:
            COLOR _RGB32(255, 255, 0)
            _PRINTSTRING (X + 10, (Y + 20 * height) + 50), OnScreenDrives$
            COLOR _RGB32(255, 205, 249)
            CWD$ = _CWD$
            IF LEN(CWD$) > lenght THEN CWD$ = LEFT$(CWD$, lenght - 3) + LTRIM$("...")
            _PRINTSTRING (X + 10, (Y + 20 * height) + 70), CWD$
        END IF

        LINE (X + 1, Y + 1)-(X + 3 + (8 * lenght) + 16, Y + 3 + (20 * height) + 90), , B
        LINE (X + 4, Y + 4)-(X + (8 * lenght) + 16, Y + (20 * height) + 90), , B
        LINE (X + 4, Y + (height * 20) + 40)-(X + (8 * lenght) + 16, Y + (height * 20) + 40), , B



        _LIMIT 80
    LOOP
END FUNCTION

FUNCTION LoadDrives$ (drives() AS STRING)
    IF INSTR(_OS$, "[WINDOWS]") THEN
        SHELL _HIDE CHR$(34) + "wmic logicaldisk get name" + CHR$(34) + ">TempDirList.txt"
        REDIM drives(0) AS STRING

        OPEN "TempDirList.txt" FOR INPUT AS #1
        LINE INPUT #1, junk$ 'First line is  name
        counter = 0
        DO UNTIL EOF(1)
            counter = counter + 1
            INPUT #1, junk$ 'drive name
            REDIM _PRESERVE drives(counter) AS STRING
            IF LEN(junk$) > 1 THEN junk$ = MID$(junk$, 2, 1) + ":" ELSE junk$ = "": counter = counter - 1
            IF junk$ <> "" THEN
                drives(counter) = junk$
            END IF
        LOOP
        CLOSE #1
        KILL "TempDirList.txt"

        FOR manual = 1 TO counter
            LoadDrives$ = LoadDrives$ + LEFT$(drives(manual), 1)
        NEXT
    END IF
END FUNCTION

SUB GetFileList (SearchDirectory AS STRING, DirList() AS STRING, FileList() AS STRING)
    CONST IS_DIR = 1
    CONST IS_FILE = 2
    DIM flags AS LONG, file_size AS LONG

    REDIM _PRESERVE DirList(100), FileList(100)
    DirCount = 0: FileCount = 0

    IF load_dir(SearchDirectory) THEN
        DO
            length = has_next_entry
            IF length > -1 THEN
                nam$ = SPACE$(length)
                get_next_entry nam$, flags, file_size
                IF flags AND IS_DIR THEN
                    DirCount = DirCount + 1
                    IF DirCount > UBOUND(DirList) THEN REDIM _PRESERVE DirList(UBOUND(DirList) + 100)
                    DirList(DirCount) = nam$
                ELSEIF flags AND IS_FILE THEN
                    FileCount = FileCount + 1
                    IF FileCount > UBOUND(filelist) THEN REDIM _PRESERVE FileList(UBOUND(filelist) + 100)
                    FileList(FileCount) = nam$
                END IF
            END IF
        LOOP UNTIL length = -1
        close_dir
    ELSE
    END IF
    REDIM _PRESERVE DirList(DirCount)
    REDIM _PRESERVE FileList(FileCount)
END SUB