Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How check for valid file name
Message
From
20/11/2000 00:55:16
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00443211
Message ID:
00443535
Views:
13
>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
      *  OK
      =FCLOSE(nFH)
      ERASE (cTempDir+'\'+cFileNameToTest)
   ENDIF
   RMDIR (cTempDir)
ENDIF
ON ERROR &cOldErrorHandler
RETURN nFH > 0
>
>Thanks
>
>Brenda
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform