Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Assembler015

Directory Format

This topic is 5957 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m working on a win32 application and I was wondering if there was an API call to validate a directory. I don''t care if the directory exists or not, I just want to know if the format of the entered directory is valid. I''ve looked in the MSDN library but I haven''t had much luck locating any API call to do this and right now I''m more interested in working on the program rather than writting a function to make sure the string is of valid format to be a directory. Thanks for any help --Andrew

Share this post


Link to post
Share on other sites
Advertisement
Thanks for the reply however, I''ve seen that function before and that tells you if the path is valid only if the directory exists - I don''t care if it does or doesn''t. Does any one know of a function to do this?

thanks
--Andrew

Share this post


Link to post
Share on other sites
Here, I wrote one. It may not be perfect, since I may have screwed up the ''allowed characters'' part (I found the information online, but I didn''t put much effort into insuring its correctness). It''s easy to make it handle unix-style directory characters (which Windows doesn''t mind as far as I know), by adding a check for ''/'' in all the places that check against ''\\''. It seems to work, but it isn''t heavily tested.

  
int IsValidWindowsPath(const char *Path) {
const char DirChar = ''\\'';
const char Allowed[] = { ''$'', ''%'', ''\'''', ''`'', ''-'',
''@'', ''{'', ''}'', ''~'', ''!'',
''#'', ''('', '')'', ''&'', ''_'',
''^'', ''+'', '','', ''.'', ''='',
''['', '']'', '' '' };
unsigned int a;

/* Handle Drive Dealies */
if(Path[1] == '':'') {
if(tolower(Path[0]) < ''a'' || tolower(Path[0]) > ''z'' ||
Path[2] != DirChar) {
return 0;
}
Path += 3;
}

while(*Path) {
if(Path[0] == ''.'') {
/* Handle Current Directory and Parent Directory References */

if(Path[1] == DirChar || Path[1] == ''\0'')
Path += 3;
else if(Path[1] == ''.'')
if(Path[2] == DirChar || Path[2] == ''\0'')
Path += 4;
else return 0;
else return 0;
} else {
while(Path[0] != DirChar && Path[1] != ''\0'') {
if(tolower(Path[0]) < ''a'' || tolower(Path[0]) > ''z'') {
for(a=0; a<sizeof(Allowed); ++a) {
if(Path[0] == Allowed[a])
goto continue_2;
}
return 0;
}
continue_2:;
++Path;
}
if(Path != ''\0'')
++Path;
}
}

return 1;
}


Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!