Browse through directories

Gizmo

New Member
Hello,

I would like to know how I can do the following:

I have a directory C:\tmp and I would like to know all subdirectories.

eg. C:\tmp\TEST1
C:\tmp\TEST2
...

Can I use a certain loop for this? With DOS commands?

Thanks,

SB.
 

bendaluz2

Member
Here is some code to do a recursive search for directories. It is fairly simple and quick for most applications, though it can be fairly slow on very large trees. In this case I think using an operating system command would be more efficient.
Code:
DEFINE VARIABLE c$dirs AS CHARACTER NO-UNDO INITIAL "c:\tmp".
DEFINE VARIABLE c$rec AS CHARACTER NO-UNDO.

DEFINE TEMP-TABLE tbl$dirs NO-UNDO
    FIELD c$dir AS CHARACTER FORMAT "X(60)"
    INDEX idx$main IS PRIMARY UNIQUE c$dir.

DEFINE STREAM stm$in.

DO WHILE c$dirs <> "":
    INPUT STREAM stm$in FROM OS-DIR(ENTRY(1,c$dirs,"|")).
    REPEAT:
        IMPORT STREAM stm$in UNFORMATTED c$rec.
        IF TRIM(ENTRY(5,c$rec,'"')) = "D" THEN /* Process Dirs */
        DO:
            IF TRIM(ENTRY(2,c$rec,'"')) <> "."
                AND TRIM(ENTRY(2,c$rec,'"')) <> ".." THEN
            DO:
                ASSIGN c$dirs = c$dirs + "|" + TRIM(ENTRY(4,c$rec,'"')).
                CREATE tbl$dirs.
                ASSIGN tbl$dirs.c$dir = TRIM(ENTRY(4,c$rec,'"')).
            END.
        END.
        IF TRIM(entry(5,c$rec,'"')) = "F" THEN /* Process Files */
        DO:
        END.
    END.
    INPUT STREAM stm$in CLOSE.
    ASSIGN ENTRY(1,c$dirs,"|") = ""
           c$dirs = SUBSTRING(c$dirs,2).
END.

FOR EACH tbl$dirs
    NO-LOCK:
    DISP tbl$dirs.
END.

Gizmo said:
Hello,

I would like to know how I can do the following:

I have a directory C:\tmp and I would like to know all subdirectories.

eg. C:\tmp\TEST1
C:\tmp\TEST2
...

Can I use a certain loop for this? With DOS commands?

Thanks,

SB.
 
Top