Colleagues!
We are all using the built-in function FILE() in VFP for checking the existence of certain file, ain't we? I found lately that it's not fit for the cases when we either do not know exactly the file name and/or extension, or need just to find out if a group of files with common name or extension exists. For instance, we want to check if any file with DBF extension exists in the directory lcSomePath, and we either do not know or do not care the file(s) name(s). Wouldn't it be nice to have the possibility to issue just
and get the result? But FILE() function does not take wildcards. Therefore, I wrote custom function FileX(), which essentially is a wrapper for ADIR() built-in function that DOES take wildcards. Here it is:
You are invited to copy-paste this function and use it any way you like, free of charge.
I just thought it may be helpful in certain situations.
Any comments, or suggestions for refinements are quite welcome!
Regards,
Ilya
We are all using the built-in function FILE() in VFP for checking the existence of certain file, ain't we? I found lately that it's not fit for the cases when we either do not know exactly the file name and/or extension, or need just to find out if a group of files with common name or extension exists. For instance, we want to check if any file with DBF extension exists in the directory lcSomePath, and we either do not know or do not care the file(s) name(s). Wouldn't it be nice to have the possibility to issue just
Code:
?FILE(lcSomePath + "*.DBF")
Code:
******************************************************************************************************************************
FUNCTION FileX(tcPath)
******************************************************************************************************************************
** Function Name : File eXtended
** Purpose : Determines if the file with the given name (regardles of extension or wildcard characters) exists.
** Description : Extended version of the standard FILE() function. Takes any extension or any legal wildcard.
** Parameter(s) : Full path as string.
** Return : Success as Boolean.
** Side Effect(s): Shan't be any.
** Notes: : Generates no error messages on its own.
******************************************************************************************************************************
&& Parameter validation:
IF TYPE('tcPath') # "C"
RETURN .F.
ENDIF
tcPath = ALLTRIM(tcPath)
IF EMPTY(tcPath)
RETURN .F.
ENDIF
&& The following statement is for VFP 6.0 and higher
** tcPath = ADDBS(tcPath)
&& The followiing is for VFP 3.0 and earlier versions of FoxPro
**IF RIGHT(tcPath, 1) # "\"
** tcPath = tcPath + "\"
**ENDIF
&& Un-comment whichever statement above fits your version if FoxPro
LOCAL ARRAY laFile[1]
LOCAL lnMax
lnMax = ADIR(laFile, tcPath)
RELEASE ALL LIKE laFile*
RETURN (lnMax > 0)
ENDFUNC
******************************************************************************************************************************
![[smile] [smile] [smile]](/data/assets/smilies/smile.gif)
Any comments, or suggestions for refinements are quite welcome!
Regards,
Ilya