Solved

DOS/Windows Filenames

Posted on 1998-07-17
5
274 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
unable to delete all specified values regedit 38 893
isEverywhere  challenge 19 91
has77  challenge 9 104
Dell Alienware Graphics Amplifier Driver for non-Alienware systems 18 645
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: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

739 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