>How to tell if they entered a valid filename? What are the limitations? Only alpha and numeric? They are entering a file name in a textbox (the file may not exist) and I want to check it for being valid.
That's going to depend on the file system you're writing to; an older DOS or NetWare volume may only accept old DOS-style 8.3 file names, Win32 files systems accept file names with much greater flexibility, and other platforms vary in their rules.
A trick I use to check for file name legality is to create a unique, temporary directory name beneath the target directory, and try to FCREATE() the file in the temporary directory:
FUNCTION TestFileName(tcFileNameToTest, tcTargetPath)
LOCAL cTempDir, nFH, cOldErrorHandler
IF TYPE(tcFileNameToTest) # 'C'
RETURN .F.
ENDIF
cTempDir = ADDBS(FULLPATH(IIF(TYPE(tcTargetPath) # 'C' OR LEN(tcTargetPath) = 0,'.',tcTargetPath))+SYS(3)
DO WHILE DIRECTORY(cTempDir)
cTempDir = LEFT(cTempDir,RAT('\',cTempDir))+SYS(3)
ENDDO
cOldErrorHandler = ON('ERROR')
nFH = 0
ON ERROR nFH = -1
MKDIR (cTempDir)
IF nFH = 0
nFH = FCREATE(cTempDir+'\'+cFileNameToTest)
IF nFH > 0
=FCLOSE(nFH)
ERASE (cTempDir+'\'+cFileNameToTest)
ENDIF
RMDIR (cTempDir)
ENDIF
ON ERROR &cOldErrorHandler
RETURN nFH > 0
>
>Thanks
>
>Brenda