Re: directory tree

 BBS: Inland Empire Archive
Date: 12-08-92 (19:11)             Number: 379
From: RICK COOPER                  Refer#: NONE
  To: STEVE DEMO                    Recvd: NO  
Subj: Re: directory tree             Conf: (2) Quik_Bas
-=[Clever Quote Headers Make Me Gag! From : Steve Demo][To : Paul Lankow]=-
>  I do have one question, Is it possible to find out what Drive and Dir
>  you are in with out doing the following:
>


The following code will do what you wish.. remember to load
QB with the /lQB switch (QB /lQB)

DECLARE FUNCTION CurrentDir$ ()
'$INCLUDE: 'QB.BI'
PRINT CurrentDir$

FUNCTION CurrentDir$
DIM InRegs AS RegTypeX, OutRegs AS RegTypeX
'====================================================================
' This Function Will Return The Current Path With A Complete Path Spec
' Including Drive And Trailing "\"
' If You Don't Want The trailing "\" Then Use A Left$ Statement To
'Remove It... E.G. Dir$ = Left$(CurrentDir$,Len(CurrentDir$) - 1)
'===================================================================

InRegs.ax = &H1900                         'Use Dos Function To Get
CALL INTERRUPTX(&H21, InRegs, OutRegs)     'Current Drive
Drive% = (OutRegs.ax AND &HFF) + 1         'Function Returns 0 Based
                                           'Drive Number And Next
                                           'Function needs A 1 Based
                                           'Number So We Add 1 To Result

Drive$ = CHR$(64 + Drive%)                 'Create String Representation
                                           'In Uppercase, Of Current
                                           'Drive Number

Directory$ = SPACE$(64)                    'Create Scratch Buffer

InRegs.ax = (256 * &H47) + 0               'Load Function Number
InRegs.dx = (256 * 0) + Drive%             'Load Drive Number
InRegs.ds = VARSEG(Directory$)             'Pointer To A 64 Byte
InRegs.si = SADD(Directory$)               'Scratch Buffer
CALL INTERRUPTX(&H21, InRegs, OutRegs)     'Call Dos Int. 21 Func. 47

spot = INSTR(Directory$, CHR$(0))          'Function Returns An ASCIIZ
IF spot <> 0 THEN                          'String And We Don't Want The
  Directory$ = LEFT$(Directory$, spot - 1) 'Terminating Null Character
END IF                                     'So This Removes It And
                                           'Trailing Spaces

IF LEN(Directory$) > 1 THEN                'If It Isn't The Root Then
                                           'We Add A Trailing "\"

CurrentDir$ = Drive$ + ":\" + Directory$ + "\"

ELSE                                       'If It Is The Root We Don't
CurrentDir$ = Drive$ + ":\" + RTRIM$(LTRIM$(Directory$))
END IF                                     'Done!


END FUNCTION


=============================[ Cut Here ]====================================

This will return the current directory complete with drive designator.

Rick

--- T.A.G. 2.6c3e Beta
 * Origin: Just For The Heck Of It II   -=(Fort Wayne In)=- (1:236/16)
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