Need directory > variable

 BBS: Inland Empire Archive
Date: 01-10-93 (21:20)             Number: 286
From: MATT HART                    Refer#: NONE
  To: ALEX MCNEILLY                 Recvd: NO  
Subj: Need directory > variable      Conf: (2) Quik_Bas
 AM> Is there a way to get a listing of files in a directory and put
 AM> it into a variable (or array) WITHOUT being listed on the screen?

'
' GETFILES.BAS  by Matt Hart
' Uses SrchFile and SrchNext to load an array with file names.
' Also CountFiles so you can DIM an array to match the number
' of file names.
'
    DEFINT A-Z
    TYPE RegTypeX
        ax    AS INTEGER
        bx    AS INTEGER
        cx    AS INTEGER
        dx    AS INTEGER
        bp    AS INTEGER
        si    AS INTEGER
        di    AS INTEGER
        flags AS INTEGER
        ds    AS INTEGER
        es    AS INTEGER
    END TYPE
    TYPE DTAType
        A AS STRING * 42
    END TYPE

' ---------------- Sample Code
    Srch$ = RTRIM$(LTRIM$(COMMAND$))
    IF Srch$ = "" THEN Srch$ = "*.*"
    CALL CountFiles(Srch$,NumFiles)
    Print NumFiles
    if NumFiles=0 then END
    REDIM Files$(0 to NumFiles) : Files$(0)=Srch$
    CALL GetFiles(Files$())
    For i=1 to NumFiles : Print Files$(i) : Next i
    END
' -----------------------------

SUB CountFiles (Srch$,NumFiles)
    DIM DTA as DTAType
    NumFiles=0
    CALL SrchFile (Srch$,File$,DTA,Ecode)
    DO UNTIL Ecode
        NumFiles=NumFiles+1
        CALL SrchNext(File$,DTA,Ecode)
    LOOP
    NumFiles=NumFiles-1
END SUB
SUB GetFiles(Files$())
    DIM DTA as DTAType
    Srch$=Files$(0)
    CALL SrchFile (Srch$,File$,DTA,Ecode)
    C=0
    DO UNTIL Ecode
        Files$(C)=File$
        C=C+1
        CALL SrchNext (File$,DTA,Ecode)
    LOOP
END SUB
SUB SrchFile (Srch$,File$,DTA as DTAType,Ecode)
    DIM InRegs as RegTypeX
    DIM OutRegs as RegTypeX
    DIM F as string * 64
    InRegs.AX = &H1A00
    InRegs.DS = VARSEG(DTA)
    InRegs.DX = VARPTR(DTA)
    CALL InterruptX (&H21, InRegs, OutRegs)
    F = Srch$+CHR$(0)
    InRegs.AX = &H4E00
    InRegs.CX = 0
    InRegs.DS = VARSEG(F)
    InRegs.DX = VARPTR(F)
    CALL InterruptX (&H21, InRegs, OutRegs)
    File$ = MID$( DTA.A,31 )
    File$ = LEFT$(File$, INSTR(File$+CHR$(0),CHR$(0))-1)
    Ecode = OutRegs.AX
END SUB
SUB SrchNext (File$,DTA as DTAType,Ecode)
    DIM InRegs as RegTypeX
    DIM OutRegs as RegTypeX
    DIM F as string * 64
    F = Srch$+CHR$(0)
    InRegs.AX = &H4F00
    CALL InterruptX (&H21, InRegs, OutRegs)
    File$ = MID$( DTA.A, 31 )
    File$ = LEFT$(File$, INSTR(File$+CHR$(0),CHR$(0))-1)
    Ecode = OutRegs.AX
END SUB
---
 * Origin: Midnight Micro!  V.32/REL  (918)451-3306 (1:170/600)
Outer Court
Echo Basic Postings

Books at Amazon:

Back to BASIC: The History, Corruption, and Future of the Language

Hackers: Heroes of the Computer Revolution (including Tiny BASIC)

Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution

The Advent of the Algorithm: The Idea that Rules the World

Moths in the Machine: The Power and Perils of Programming

Mastering Visual Basic .NET