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( | 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 | 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 <> | IF mfilename <> "" | ||
position = LEN(mfilename) | position = LEN(mfilename) | ||
char = | char = " " | ||
DO WHILE char <> | DO WHILE char <> ":" | ||
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 | 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() FunctionID: Q103683 The information in this article applies to:
SUMMARYThe 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 INFORMATIONTo 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 PROCEDUREFoxPro for MS-DOS and FoxPro for WindowsPROCEDURE 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+/MacPROCEDURE 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 |