Re: DIR$ Help 1/

 BBS: Inland Empire Archive
Date: 07-19-92 (07:19)             Number: 54
From: MICHAEL MALLEY               Refer#: NONE
  To: BOB SEWELL                    Recvd: NO  
Subj: Re: DIR$ Help         1/       Conf: (2) Quik_Bas
BS>except figuring out a good algorythm to find all the
BS>directories on a disk. Going to be some tricky code...

Hello Bob!  Long time not chat [Grin].  Feel free to cut and paste:

- Michael  :)

  -------------------------[ TREE.BAS ]------------------------------

'Title:   TREE.BAS
'Purpose: Shows a graphical representation of the directory structure.
'By:      Michael Malley
'Written: April 13, 1992
'
'Note:  Redirection to devices is enabled.
'
'Released into the public domain as long as the intial screen is kept
'intact.  Use of the algorithms in other applications may be used without
'acknowledgment as long as that application is sufficiently different in
'purpose than TREE.

DECLARE SUB SetDTA (Segment%, Offset%)
DECLARE SUB ShowTree (PathSpec$, Position AS INTEGER)
DECLARE FUNCTION GetFile$ (Spec$, DTA AS ANY, FileNames AS INTEGER)

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
DECLARE SUB InterruptX (intnum AS INTEGER, Inreg AS RegtypeX, Outreg AS_
  RegtypeX)

TYPE DTAType
    Junk  AS STRING * 21
    Attr  AS STRING * 1
    Time  AS INTEGER
    Date  AS INTEGER
    Size  AS LONG
    Name  AS STRING * 13
END TYPE

CONST False = 0
CONST True = NOT False

'--- Give enough of a stack for the recursion for all but the most trashed
'    directories
STACK 6144

DIM SHARED Regs AS RegtypeX, Levels AS STRING * 32, ScratchDTA AS DTAType
DIM SHARED ErrorLevel AS INTEGER, ShowFiles, KeyStroke AS STRING
DIM Spec AS STRING

'--- Levels:      a string of flags 32 characters long.  Used to allow child
'                 occurences of ShowTree to know what graphic lines must be
'                 drawn.  Using a string results in a savings of memory of
'                 32 bytes and faster execution then when we use an array.
'
'    ErrorLevel:  Used internally to pass DOS errors while getting
'                 directory information.
'
'    Spec:        The initial pathspec to be used in the directory search.
'
'    ScratchDTA:  DTA used to retrieve filenames
'
'    ShowFiles:   Flag to determine if we show filenames also

Spec = RTRIM$(COMMAND$)

IF LEN(Spec) THEN
    Position = INSTR(Spec, "/F")
    IF Position THEN
        ShowFiles = True
        IF Position = 1 THEN
            Spec = LTRIM$(RIGHT$(Spec, LEN(Spec) - (INSTR(Spec, "/F") + 1)))
        ELSE
            Spec = RTRIM$(LEFT$(Spec, Position - 1))
        END IF
    END IF
END IF

IF LEN(Spec) = 0 THEN Spec = CURDIR$    '--- QB users use "." for Spec

PRINT "TREE ver 1.0 Copyright(C) 1992 - Use /F for file listing."
PRINT "By: Michael S. Malley and released into the public domain."
PRINT
PRINT Spec

'--- Chop off any trailing \
IF ASC(RIGHT$(Spec, 1)) = 92 THEN Spec = LEFT$(Spec, LEN(Spec) - 1)


'--- Sets the level of searching and returns any errors on the first call
Position = 1
ShowTree Spec, Position

SELECT CASE Position
    CASE &H3
        PRINT "Invalid path"
    CASE &H12
        PRINT "No Directories"
END SELECT
END

FUNCTION GetFile$ (Spec$, DTA AS DTAType, FileNames AS INTEGER)

'--- If a pathspec is sent, start with a search for a new file.
IF LEN(Spec$) THEN

    SetDTA VARSEG(DTA), VARPTR(DTA)

    Regs.ax = &H4E00
    Regs.cx = &H10
    IF FileNames THEN Regs.cx = &H6
    '--- QB users use VARSEG
    Regs.ds = SSEG(Spec$)
    Regs.dx = SADD(Spec$)

    CALL InterruptX(&H21, Regs, Regs)

    IF Regs.flags AND 1 THEN
        ErrorLevel = Regs.ax
        EXIT FUNCTION
    END IF

    '--- If the first file returned is a directory, get the name and
    '    find out if it is a valid directory
    IF (ASC(DTA.Attr) AND &H10) = &H10 OR FileNames THEN GOSUB ExtractName
END IF

DO UNTIL ExitFlag
    SetDTA VARSEG(DTA), VARPTR(DTA)
    '--- Try to find another file
    Regs.ax = &H4F00
    CALL InterruptX(&H21, Regs, Regs)
>>> Continued to next message

 * SLMR 2.1a * I am the terror that posts in the night!

--- Maximus 2.00
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