Microsoft KB Archive/103683

From BetaArchive Wiki

How to Return Only the Filename from GETFILE() Function

ID: Q103683

The information in this article applies to:

  • Microsoft FoxPro for MS-DOS, versions 1.02, 2.0, 2.5, and 2.5a
  • Microsoft FoxPro for Windows, versions 2.5 and 2.5a
  • Microsoft FoxBASE+ for the Macintosh, version 2.01

SUMMARY

The GETFILE() function returns the whole path and filename of a selected file. To return only the filename, you can use the procedure shown below to remove the path information.

MORE INFORMATION

To return only the filename for the GETFILE() function, you can establish the sample FILENAME procedure shown below in a procedure file. The following code demonstrates how to call the FILENAME() function in a program:

   fvar = filename(GETFILE())
   ? fvar

SAMPLE CODE FOR THE FILENAME PROCEDURE

FoxPro for MS-DOS and FoxPro for Windows

   PROCEDURE filename
   PARAMETER mfilename
   SET TALK OFF
   IF .NOT. EMPTY(mfilename)
      position = RAT("\",mfilename)
      mfname = SUBSTR(mfilename,position+1)
      mpath = SUBSTR(mfilename,1,position)
      RETURN mfname  && Modify to 'RETURN mpath' to return path only
   ELSE
      RETURN "No File Was Selected"
   ENDIF

FoxBASE+/Mac

   PROCEDURE filename
   PARAMETER mfilename
   SET TALK OFF
   SET EXACT ON
      IF mfilename <> ""
         position = LEN(mfilename)
         char = " "
         DO WHILE char <> ":"
            char = SUBSTR(mfilename,position,1)
            position = position - 1
         ENDDO
         mfname = SUBSTR(mfilename,position+2,(LEN(mfilename) ;
            - (position +2)))
         mpath = SUBSTR(mfilename,2,position) && Modify to 'RETURN ;
            mpath' to return path only
         RETURN mfname
      ELSE
         RETURN "No file was selected"
      ENDIF
   SET EXACT OFF

Additional reference words: FoxDos FoxWin 1.02 2.00 2.50 2.50a KBCategory: kbprg KBSubcategory: FxprgGeneral


Last Reviewed: June 27, 1995
© 1999 Microsoft Corporation. All rights reserved. Terms of Use.