Solved

DOS/Windows Filenames

Posted on 1998-07-17
5
250 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
ID: 1319403
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
ID: 1319404
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
ID: 1319405
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
ID: 1319406
Thanks!!
0
 
LVL 7

Expert Comment

by:psdavis
ID: 1319407
Accepted answer?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to calculate times for developing software? 8 66
iSeries DB2 Query 2 91
has77  challenge 9 73
Detect file exist or not 3 134
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

863 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

22 Experts available now in Live!

Get 1:1 Help Now