Click to See Complete Forum and Search --> : CFileDialog


domi
April 17th, 1999, 04:21 AM
Hello,

I want to get the full filename (w/ path) of a selected file in a CFileDialog, but without
the extension (like .txt) !

CFileDialog::GetFileTitle() does, but then I have no path to the file. CFileDialog::GetPathName() receives the full path and the filename, but with the extension.

Is there any way to do what I want ?

Thanks, Dominik

Dominik Rothert
E-Mail: domi@netcologne.de

Lynx
April 17th, 1999, 05:44 AM
Try this:

CString fullname = CFileDialog::GetPathName(); // full path with filename
CString filename = CFileDialog::GetFileName(); // filename only
int pos = filename.ReverseFind('.'); // only find the last '.', if any
if(pos > 0){ // make sure the filename has extension
pos = fullname.ReverseFind('.');
// now get rid of extension
fullname.Left(pos); // remove the extension from filename
}


The above codes may not cover all knid of cases, for example, a file has more than one extension (text.dat.dat). Also, you can call C library function:
void _splitpath( const char *path, char *drive, char *dir, char *fname, char *ext );

to extract the full path w/ filename into separate strings and format to the string you want.

Hope this will help. Good luck.

Lynx

raju sungar
January 25th, 2002, 01:45 AM
hi I want a File/Directory select dialog to appear after pressing a button ,and I want to store the path into buffer.I am in urgent need of this
thanks
RAJU