Solved

DOS/Windows Filenames

Posted on 1998-07-17
5
281 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

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…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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 video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

632 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