Announcement

Collapse
No announcement yet.

What is the name of my running pbdos exe?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • What is the name of my running pbdos exe?

    Ive searched far and wide but couldnt find any hint of source code to do what is a very straightforward thing in pbcc/pbdll !
    My program needs to determine its filename. For example,
    Code:
    $COMPILE EXE
    PRINT "Filename = " & Exename$
    And if I ran the compiled exe from c:\file.exe, then the output would say:
    Filename = c:\file.exe

    Thanks in advance!


    ------------------
    -

  • #2
    Greetings Again!

    Wayne:
    Ive searched far and wide but couldnt find any hint of source code to...determine its filename.
    I'm kind of partial to the code listed by Michael Mattias found here.

    I've edited it lightly to mimic what you want:

    Code:
    PRINT "Filename = "; ExeFileName$
    
    FUNCTION ExeFileName$ LOCAL PUBLIC
      REG 1, &h6200                        'set AX = &6200 function &62
      CALL INTERRUPT &h21                  'call DOS: returns....
      EnvSeg = REG( 2 )                    'environment segment in bx
      DEF SEG = EnvSeg
      EnvPtr& = CLNG( PEEKI( 44 ))         'bytes 44,45 of envseg
      DEF SEG = EnvPtr&                    'set segment here
      Byte = 0
      DO                                   'search for two zero bytes in a row
        IF Peek( Byte ) = 0 THEN
          IF PEEK( Byte + 1 ) = 0 THEN
            INCR Byte, 2
            EXIT LOOP
          END IF
        END IF
        INCR Byte, 1
      LOOP
    
      IF PEEK( byte ) = 1 THEN             'if next byte is 1, then the program
        INCR Byte, 2                       'program name follows.
        Temp$ = STRING$( 128, 0 )          'set up a buffer
        Ptr = 0
        DO
          IF PEEK( Byte ) = 0 THEN         'the name is ASCII-Z terminated (CHR$(0))
            EXIT LOOP                      'if it ain't terminated, read it in
          ELSE                             'a byte at a time.
            INCR Ptr, 1
            MID$( temp$, ptr, 1 ) = CHR$( PEEK( Byte ))
            INCR Byte
          END IF
        LOOP
        ExeFileName$ = LEFT$( Temp$, ptr ) 'strip trailing chr$(0)
      ELSE                                 'error: return the null string
        ExeFileName$ = ""
      END IF
      DEF SEG                              'restore default data segment
    END FUNCTION 'ExeFileName$

    ------------------
    Don Ewald
    mailto:[email protected][email protected]</A>
    Donnie Ewald
    [email protected]

    Comment


    • #3
      Strewth! That's quite complex, but works very well nonetheless. Thanks very much Don and thanks Michael, I can get back to work now


      ------------------
      -

      Comment


      • #4
        Old code never dies, it just appears on some BBS, somewhere...

        From my source code file ...

        Code:
        ' file:exename.bas. creates a UNIT which can be linked which has the
        ' FUNCTION ExeName$. Exename$ returns the fully qualified DOS file name of
        ' the current program. See BasicPro Vol. 3 No. 1 (Feb/Mar 1993) page
        ' 49-50 for the code listing there.
        ' HISTORY ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        ' 02.16.93 coded (pb2.10)
        ' 01.05.94 created pb3.0c UNIT file
        ' 12.27.95 created PB 3.2 unit file RENAMED EXENAMEU
        ' 12.04.00 updated to PB 3.5
        ' ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        $STACK 2048
        MCM
        Michael Mattias
        Tal Systems Inc. (retired)
        Racine WI USA
        [email protected]
        http://www.talsystems.com

        Comment


        • #5
          Thanks very much again Mike - actually Id also be very interested in the BasicPro 'zine if it has source like that in it, do you know if it's still available anywhere?
          Thanks again, and enjoy the weekend!
          Wayne



          ------------------
          -

          Comment


          • #6
            Originally posted by Wayne Diamond:
            Ive searched far and wide but couldnt find any hint of source code to do what is a very straightforward thing in pbcc/pbdll !
            My program needs to determine its filename. For example,
            Code:
            $COMPILE EXE
            PRINT "Filename = " & Exename$
            And if I ran the compiled exe from c:\file.exe, then the output would say:
            Filename = c:\file.exe

            Thanks in advance!


            Wayne,

            Look in the File called DOSUNIT.BAS that ships with PB v3.5 in the EXTRAS
            directory. There is a function contained in that file called ExeName
            that is an ASM function and works quite well.


            Scott




            ------------------
            Scott Slater
            Summit Computer Networks, Inc.
            www.summitcn.com

            Comment

            Working...
            X