Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Validating a path/filename
Message
From
24/12/2012 16:38:39
 
 
To
24/12/2012 15:18:02
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01560549
Message ID:
01560578
Views:
102
This message has been marked as the solution to the initial question of the thread.
Likes (1)
SET STEP ON
cFilename = "C:\DOCUMENTS AND SETTINGS\RICK HODGIN\MY DOCUMENTS\MY PICTURES\This is a file name with many spaces.txt"
IF !ValidateFileName(cFilename)
    MESSAGEBOX("Invalid filename " + cFilename)
    RETURN
ENDIF

cFilename = "\\servername\dir\subdir\filename\myfile.dbf"
IF !ValidateFileName(cFilename)
    MESSAGEBOX("Invalid filename " + cFilename)
    RETURN
ENDIF


FUNCTION ValidateFileName
LPARAMETERS pFileName
LOCAL luRawDir, luRawFilename
LOCAL lcFixedFilename

	* Get our filename in WIDE/UNICODE format
	luRawDir		= STRCONV(STRCONV(PADR(JUSTPATH(pFilename),  260 * 2, CHR(0)), 1), 5)
	luRawFilename	= STRCONV(STRCONV(PADR(JUSTFNAME(pFilename), 260 * 2, CHR(0)), 1), 5)

	* Declare our requisite function (can be done once in a setup.prg somewhere)
	DECLARE INTEGER PathCleanupSpec IN shell32 STRING@ cDir, STRING@ cFilename

	* Ask Windows to fix it up for us
	PathCleanupSpec(@luRawDir, @luRawFilename)

	* Un-declare our requisite function (not needed if done in a setup.prg somewhere)
	CLEAR DLLS PathCleanupSpec
	
	luRawDir		= IIF(REPLICATE(CHR(0),3) $ luRawDir,		LEFT(luRawDir,		AT(REPLICATE(CHR(0),3), luRawDir)		+ 1),	luRawDir)
	luRawFilename	= IIF(REPLICATE(CHR(0),3) $ luRawFilename,	LEFT(luRawFilename,	AT(REPLICATE(CHR(0),3), luRawFilename)	+ 1),	luRawFilename)

	* Re-convert wide-character back to string
	lcFixedFilename	=	ADDBS(	ALLTRIM(STRCONV(STRCONV(luRawDir,      6), 2))	) + ;
								ALLTRIM(STRCONV(STRCONV(luRawFilename, 6), 2))

	RETURN (lcFixedFilename == pFilename)
ENDFUNC
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform