/*
File name check is not required for extension \ n
1 Length of 0\n
2 directory part not correct \ n
3 file name contains illegal characters \ n
4 If the extension is not *, check that the extension matches \ n
*/
BOOL Ccommonfunc::s_isvalidfilename (CString &strp, CString &strext)
{
LN Add 2005/05/18 Begin
BOOL ret;
Delete unintended characters at the beginning and end
Strp.trimleft ();
Strp.trimright ();
Check length > 0
int length = Strp.getlength ();
if (length <= 0)
{
return FALSE;
}
Check last \ Or/position
int pos = 0;
int pos1 = strp.reversefind (' \ \ ');
int pos2 = Strp.reversefind ('/');
Get Max POS
if (Pos1 > Pos2)
{
pos = POS1;
}
Else
{
pos = Pos2;
}
//Check pos
if (pos >= 0 && pos < length)
{
//valid dir
& Nbsp; ret = S_isdirectory (Strp.left (POS));
if (ret = = TRUE)
{
cstring strt = Strp.right (length-pos-1);
Valid file name
if (STRT.
Findoneof (_t ("\\/:,;*?\" <>| ")) = =-1
&& strt.getlength () > 0)
{
Check FDB
if (Strext.comparenocase (_t ("*")) = = = 0)
{
return TRUE;
}
if (Strp.right (Strext.getlength ()).
CompareNoCase (strext)! = 0)
{
STRP + = Strext;
}
return TRUE;
}
}
return FALSE;
}
return TRUE;
LN Add 2005/05/18 End
}
C + + Common code 001 isvalidfilename VC/MFC determine valid file name