Solved

DOS/Windows Filenames

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
iSeries FTP Exit Program 8 135
no14 challenge 14 66
wait notify demo infinite loop 3 108
pre4 challenge 19 99
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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
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.

813 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

10 Experts available now in Live!

Get 1:1 Help Now