Board index » cppbuilder » filename that Windows will accept

filename that Windows will accept


2004-11-12 12:40:41 AM
cppbuilder103
Hi,
I would like to verify produced filenames to see if they can exist at all
under Windows and was wondering what code is available in existing functions
to help me there.
E.g. is there a function that takes a filename as input and produces a valid
filename as output ?
E.g.. converts "file\.txt" into "file_.txt" ?
Using Windows stuff at least I'm sure I deal with foreign systems as well
that maybe support other characters etc. ??
 
 

Re:filename that Windows will accept

bool CheckUnRegularCharactersInName( const char *cName )
{
if ( strchr( cName, '\\' ) || strchr( cName, '/' ) ||
trchr( cName, ':' ) ||
strchr( cName, '*' ) || strchr( cName, '?' ) ||
trchr( cName, '"' ) ||
strchr( cName, '<' ) || strchr( cName, '>' ) ||
trchr( cName, '|' ) )
{
return ( true ); // Invalid File Name
}
else
{
return ( false ); // Valid File Name
}
}
bool ReplaceUnRegularCharactersInName( char *cName )
{
bool bRetVal = false;
char *p;
while( ( p = strchr( cName, '\\' ) ) != 0 ) { *p = '_'; bRetVal =
true; }
while( ( p = strchr( cName, '/' ) ) != 0 ) { *p = '_'; bRetVal =
true; }
while( ( p = strchr( cName, ':' ) ) != 0 ) { *p = '_'; bRetVal =
true; }
while( ( p = strchr( cName, '*' ) ) != 0 ) { *p = '_'; bRetVal =
true; }
while( ( p = strchr( cName, '?' ) ) != 0 ) { *p = '_'; bRetVal =
true; }
while( ( p = strchr( cName, '"' ) ) != 0 ) { *p = '_'; bRetVal =
true; }
while( ( p = strchr( cName, '<' ) ) != 0 ) { *p = '_'; bRetVal =
true; }
while( ( p = strchr( cName, '>' ) ) != 0 ) { *p = '_'; bRetVal =
true; }
while( ( p = strchr( cName, '|' ) ) != 0 ) { *p = '_'; bRetVal =
true; }
return bRetVal;
}
Best regards,
Vladimir Stefanovic
Peter < XXXX@XXXXX.COM >wrote in message
Quote
Hi,

I would like to verify produced filenames to see if they can exist
at all
under Windows and was wondering what code is available in existing
functions
to help me there.
E.g. is there a function that takes a filename as input and produces
a valid
filename as output ?
E.g.. converts "file\.txt" into "file_.txt" ?
Using Windows stuff at least I'm sure I deal with foreign systems as
well
that maybe support other characters etc. ??


 

Re:filename that Windows will accept

Some corrections... All trchr should be strchr, like:
All:
Quote
trchr( cName, ':' ) ||
Should be:
strchr( cName, ':' ) ||
Best regards,
Vladimir Stefanovic
 

{smallsort}

Re:filename that Windows will accept

Surely there are more charachters not supported ... or not ???
I mean there can be characters in a string that simply don't even display
properly ?
"Vladimir Stefanovic" < XXXX@XXXXX.COM >wrote in message
Quote
bool CheckUnRegularCharactersInName( const char *cName )
{
if ( strchr( cName, '\\' ) || strchr( cName, '/' ) ||
trchr( cName, ':' ) ||
strchr( cName, '*' ) || strchr( cName, '?' ) ||
trchr( cName, '"' ) ||
strchr( cName, '<' ) || strchr( cName, '>' ) ||
trchr( cName, '|' ) )
{
return ( true ); // Invalid File Name
}
else
{
return ( false ); // Valid File Name
}
}

bool ReplaceUnRegularCharactersInName( char *cName )
{
bool bRetVal = false;
char *p;

while( ( p = strchr( cName, '\\' ) ) != 0 ) { *p = '_'; bRetVal =
true; }
while( ( p = strchr( cName, '/' ) ) != 0 ) { *p = '_'; bRetVal =
true; }
while( ( p = strchr( cName, ':' ) ) != 0 ) { *p = '_'; bRetVal =
true; }
while( ( p = strchr( cName, '*' ) ) != 0 ) { *p = '_'; bRetVal =
true; }
while( ( p = strchr( cName, '?' ) ) != 0 ) { *p = '_'; bRetVal =
true; }
while( ( p = strchr( cName, '"' ) ) != 0 ) { *p = '_'; bRetVal =
true; }
while( ( p = strchr( cName, '<' ) ) != 0 ) { *p = '_'; bRetVal =
true; }
while( ( p = strchr( cName, '>' ) ) != 0 ) { *p = '_'; bRetVal =
true; }
while( ( p = strchr( cName, '|' ) ) != 0 ) { *p = '_'; bRetVal =
true; }

return bRetVal;
}




Best regards,
Vladimir Stefanovic

Peter < XXXX@XXXXX.COM >wrote in message
news:41939608$ XXXX@XXXXX.COM ...
>Hi,
>
>I would like to verify produced filenames to see if they can exist
at all
>under Windows and was wondering what code is available in existing
functions
>to help me there.
>E.g. is there a function that takes a filename as input and produces
a valid
>filename as output ?
>E.g.. converts "file\.txt" into "file_.txt" ?
>Using Windows stuff at least I'm sure I deal with foreign systems as
well
>that maybe support other characters etc. ??
>
>


 

Re:filename that Windows will accept

Quote
Surely there are more charachters not supported ...
or not ??? I mean there can be characters in a string
that simply don't even display properly ?
These characters (I gave you) are NOT supported by Win OS
for sure for filenames.
If you have for example Cyrilic keybaord you CAN under XP
make the folder which can be created and accessed. BUT, if
some other user on internet/intranet hasn't installed the coresponding
language support, he will not be able to access the same folder,
and that's *completely* other story.
Best regards,
Vladimir Stefanovic