Solved

DOS/Windows Filenames

Posted on 1998-07-17
5
239 Views
Last Modified: 2013-11-20
Is there a function to tell if a filename is invalid??  The reason I'm asking is because I am writing some code to save files and I want to check if the name is valid before I actually save it.
0
Comment
Question by:dlbrown051198
  • 3
  • 2
5 Comments
 
LVL 7

Accepted Solution

by:
psdavis earned 50 total points
Comment Utility
You do have the _splitpath function which will take a filename and parse it into it's respective pieces.  Then you can try the _makepath function to restore it.  

You can then check both strings to make sure the before and after info is correct.  You can also validate each section (drive number, extension, etc., individually per your requirements).

There is also CFile::GetStatus( CFileStatus&) that will validate that the file exists.

Phillip


void main( void ){   char path_buffer[_MAX_PATH];   char drive[_MAX_DRIVE];
   char dir[_MAX_DIR];   char fname[_MAX_FNAME];   char ext[_MAX_EXT];
   _makepath( path_buffer, "c", "\\sample\\crt\\", "makepath", "c" );
   printf( "Path created with _makepath: %s\n\n", path_buffer );
   _splitpath( path_buffer, drive, dir, fname, ext );
   printf( "Path extracted with _splitpath:\n" );
   printf( "  Drive: %s\n", drive );   printf( "  Dir: %s\n", dir );
   printf( "  Filename: %s\n", fname );   printf( "  Ext: %s\n", ext );}


0
 

Author Comment

by:dlbrown051198
Comment Utility
I'm actually checking only the filename portion, not the directory path.  More specifically, my users will be allowed to use international characters and I noticed that the CFile::Open() function has no problem with them.  I'm just curious as to what Windows uses to validate characters in a filenames.
0
 
LVL 7

Expert Comment

by:psdavis
Comment Utility
For Win32 filenames, and international characters, I believe once you have the filename portion, you are relatively unrestricted except for characters such as '/' and '\'.  If you do know of a restriction, place the filename in a CString variable and do a CString::FindOneOf( "/\\" ) to look for your own defined invalid characters.

Phillip

0
 

Author Comment

by:dlbrown051198
Comment Utility
Thanks!!
0
 
LVL 7

Expert Comment

by:psdavis
Comment Utility
Accepted answer?
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now