Microsoft KB Archive/103683: Difference between revisions

From BetaArchive Wiki
(importing KB archive)
 
m (Text replacement - """ to """)
Line 30: Line 30:
   SET TALK OFF
   SET TALK OFF
   IF .NOT. EMPTY(mfilename)
   IF .NOT. EMPTY(mfilename)
       position = RAT("\",mfilename)
       position = RAT("\",mfilename)
       mfname = SUBSTR(mfilename,position+1)
       mfname = SUBSTR(mfilename,position+1)
       mpath = SUBSTR(mfilename,1,position)
       mpath = SUBSTR(mfilename,1,position)
       RETURN mfname  && Modify to 'RETURN mpath' to return path only
       RETURN mfname  && Modify to 'RETURN mpath' to return path only
   ELSE
   ELSE
       RETURN "No File Was Selected"
       RETURN "No File Was Selected"
   ENDIF
   ENDIF
</pre>
</pre>
Line 44: Line 44:
   SET TALK OFF
   SET TALK OFF
   SET EXACT ON
   SET EXACT ON
       IF mfilename &lt;&gt; &quot;&quot;
       IF mfilename &lt;&gt; ""
         position = LEN(mfilename)
         position = LEN(mfilename)
         char = &quot; &quot;
         char = " "
         DO WHILE char &lt;&gt; &quot;:&quot;
         DO WHILE char &lt;&gt; ":"
             char = SUBSTR(mfilename,position,1)
             char = SUBSTR(mfilename,position,1)
             position = position - 1
             position = position - 1
Line 57: Line 57:
         RETURN mfname
         RETURN mfname
       ELSE
       ELSE
         RETURN &quot;No file was selected&quot;
         RETURN "No file was selected"
       ENDIF
       ENDIF
   SET EXACT OFF
   SET EXACT OFF

Revision as of 09:28, 20 July 2020

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.