CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: CFileDialog

  1. #1
    Join Date
    Apr 1999
    Location
    Brussels - LLN / Belgium
    Posts
    6

    CFileDialog

    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: [email protected]

  2. #2
    Join Date
    Apr 1999
    Location
    CA, USA
    Posts
    78

    Re: CFileDialog

    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



  3. #3
    Join Date
    Dec 2001
    Location
    INDIA
    Posts
    125

    Re: CFileDialog

    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

    Rajendrappa HS.
    Siemens Public Communication Networks Ltd.
    Garden City, INDIA.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured