Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Finding folders in Basic

klown777klown777 Member Posts: 10
I' using QBasic v6.22 for DOS 6.22, and i cant seem to figure out how to programically find a folder.

The basic idea that this block of code will do is to check if a folder name (supplied by user) exists, and to change the direcy to the folder if it does.

If anyone can help that would be appricated. Thanks

Comments

  • moneomoneo Member Posts: 39
    : I' using QBasic v6.22 for DOS 6.22, and i cant seem to figure out how to programically find a folder.
    :
    : The basic idea that this block of code will do is to check if a folder name (supplied by user) exists, and to change the direcy to the folder if it does.
    :
    : If anyone can help that would be appricated. Thanks
    :
    :
    The following is a tested method which you can simplify for your own needs. There are many other methods including using INTERRUPTX, as well as doing a DIR to a temporary file, like:
    DIR "cmd/c /b/ad dirname >temp"
    and then reading and checking if the desired directory name is on the temporary file.

    'How to test for the existence of a directory.
    'April 22 2005 at 8:18 PM Michael Calkins
    '-----------------------------------------------------------------------------
    DECLARE FUNCTION exist% (efile$)
    DIM SHARED MyErr AS INTEGER
    CLS
    PRINT "Written by Michael Calkins with improvements by Mac."
    PRINT
    PRINT "Enter folder name to be tested"
    PRINT "(Just press Enter when no more)"
    DO
    PRINT
    LINE INPUT folder$
    IF folder$ = "" THEN EXIT DO
    'test for "nul" in the folder
    IF exist%(folder$ + "
    ul") THEN
    PRINT "It's there"
    ELSE
    PRINT "It isn't there"
    END IF
    LOOP
    SYSTEM

    GetMyErr: 'error-handling routine
    MyErr = ERR
    RESUME NEXT

    FUNCTION exist% (efile$)
    op% = FREEFILE 'find an unused file#
    MyErr = 0: ON ERROR GOTO GetMyErr
    OPEN efile$ FOR INPUT AS op% 'open it for INPUT
    ON ERROR GOTO 0
    CLOSE op%
    IF MyErr = 0 THEN exist% = -1 ELSE exist% = 0
    END FUNCTION

    Regards..... Moneo

Sign In or Register to comment.