Finding the application path 
Author Message
 Finding the application path

How can you find the path of the folder that the program is being run from
in QBasic 4.5? I would like to do this so that I can access a file in the
same directory.

Thanks

Alex



Thu, 05 Feb 2004 07:12:03 GMT  
 Finding the application path
Not sure if QB4.5 supports it, but in QB7.1,  the CURDIR$ function will return
the current directory.
Quote:

> How can you find the path of the folder that the program is being run from
> in QBasic 4.5? I would like to do this so that I can access a file in the
> same directory.

> Thanks

> Alex



Thu, 05 Feb 2004 11:52:16 GMT  
 Finding the application path


Quote:
> How can you find the path of the folder that the program is being run from
> in QBasic 4.5? I would like to do this so that I can access a file in the
> same directory.

I early posted an answer about that issue, so check it out. The functions
CurrentDir$() and CurrentDrive$() shown below will exactly do what you want.
:-)

         Andreas

Quote:
----- Original Message -----

Newsgroups: alt.lang.basic
Sent: Saturday, June 30, 2001 12:51 PM
Subject: Re: get back to root directory





> >CHDIR "x:\" will get you to the root directory of drive x (where x is an
> >actual drive letter in your system, of course!)

> Actually, I do believe you have to use a CHDRIVE and a CHDIR to do
> this.

QB does not have a CHDRIVE command, you only can either use as SHELL command

SUB ChDrive(DriveLetter$)
  SHELL LEFT$(DriveLetter$, 1) + ":"
END SUB

or if you are using the compiler, CALL INTERRUPT to INT 21h, function AH=0Eh
is also a solution:

' $INCLUDE: 'qb.bi'
SUB ChDrive(DriveLetter$)
  DIM dosIntEin AS RegType, dosIntAus AS RegType
  dosIntEin.ax = &HE00   ' AH=0Eh
  dosIntEin.dx = ASC(UCASE$(DriveLetter$)) - ASC("A")  ' DL=Drive
  CALL INTERRUPT(&H21, dosIntEin, dosIntAus)
  ' dosIntAus.ax AND 255 contains the number of installed drives
END SUB

About CHDIR itself: This built-in BASIC command invokes INT 21h, function
3Bh: As you know, MS-DOS stores a *separate* current path for every drive.
This function only sets this path itself, the current drive remains
unchanged. So a

CHDIR "m:\archive\customer\philips"

changes the path of drive M: only but the current drive remains.

Probably, you want be able to ask the current path and drive. INT 21h,
functions AH=47h (current path), and AH=19h (current drive) provide these
information:

' $INCLUDE: 'qb.bi'

FUNCTION CurrentDrive$()
  DIM dosIntEin AS RegType, dosIntAus AS RegType
  dosIntEin.ax = &H1900
  CALL INTERRUPT(&H21, dosIntEin, dosIntAus)
  CurrentDrive$ = CHR$(ASC("A") + (dosIntAus.ax AND 255)) + ":"
END FUNCTION

FUNCTION CurrentDir$(DriveLetter$)
  DIM dosIntEin AS RegTypeX, dosIntAus AS RegTypeX, pathBuf AS STRING * 80
  dosIntEin.ax = &H4700
  dosIntEin.dx = ASC(UCASE$(DriveLetter$)) - ASC("A") + 1
  dosIntEin.ds = VARSEG(pathBuf)  ' the path will be filled in
  dosIntEin.si = VARPTR(pathBuf)
  CALL INTTERUPTX(&H21, dosIntEin, dosIntAus)
  IF dosIntAus.flags AND 1 THEN
    PRINT "An error occured: "; dosIntAus.ax
    ERROR 5
  ELSE
    CurrentDir$ = LEFT$(pathBuf, INSTR(pathBuf, CHR$(0) - 1)   ' Note: It's
a C/C++ terminated string
  END IF
END FUNCTION

Note: These code samples are drafts only, i.e. I didn't test it!

For more details, check out my article about DOS interrupts in general at

http://dreael.catty.ch/Deutsch/BASIC-Knowhow-Ecke/DOS-Interrupts.html

Note: Use http://babelfish.altavista.com/ to translate the German text.

There's also the link to Ralph Brown's interrupt homepage in it.

              Andreas



Thu, 05 Feb 2004 16:27:12 GMT  
 Finding the application path
Alex,

      Would specifying something like ....

       OPEN "./ALEX.TXT" for INPUT AS #1

       not work? The "./" basically refers to the current directory which
supposedly is where you started QB.

Anthony.

Quote:

> How can you find the path of the folder that the program is being run from
> in QBasic 4.5? I would like to do this so that I can access a file in the
> same directory.

> Thanks

> Alex



Fri, 06 Feb 2004 05:09:45 GMT  
 Finding the application path

Quote:
> How can you find the path of the folder that the program is being run from
> in QBasic 4.5? I would like to do this so that I can access a file in the
> same directory.

Such a utility can be found in the All Basic Code Archives
(http://www.allbasiccode.com). Look for "pathname of current program".

Theo Meester



Fri, 06 Feb 2004 22:40:17 GMT  
 Finding the application path


Quote:
>        OPEN "./ALEX.TXT" for INPUT AS #1

>        not work? The "./" basically refers to the current directory which
> supposedly is where you started QB.

Small correction: Should be .\ALEX.TXT resp. ".\" (MS-DOS has another
directory separator than UNIX/Linux!). Of course you can omit ".\"
completely, this is already the current path! :-) For example

OPEN "ALEX.TXT" FOR INPUT AS 1

         Andreas



Sat, 07 Feb 2004 03:28:50 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. How to Find Installed Application Path

2. Update of existing .NET App - How to find the application path?

3. Finding Application path of VB .Net project

4. Finding application path

5. Find path to application

6. Finding default file type application path

7. Setting / finding path to an Application

8. Finding the path to the application

9. Finding an application's executable name and path

10. Long Path Names give Runtime error 76 - Path not found

11. Setting the path to the path of the current application

12. using application path (app.path)

 

 
Powered by phpBB® Forum Software