Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 393
  • Last Modified:

getting selected filename with CFileDialog

Hi,
I'm using CFileDialog to let a user select multiple files for import into my application. I have the following code, but I want to know how to get just the filename of the current file being iterated over (if for example the user ctrl+clicks on multiple files to open:

void CMyApp::OnImportMultipleFiles()
{
    CFileDialog cfd(TRUE, ".txt", NULL, OFN_FILEMUSTEXIST | OFN_ALLOWMULTISELECT | OFN_NOCHANGEDIR, strFilters, this, sizeof(OPENFILENAME));

    if (cfd.DoModal() == IDOK) {
        POSITION pos = cfd.GetStartPosition();
        while (pos != NULL) {
             CString strNextPath = cfd.GetNextPathName(pos);

             // How do you get just the file name here of the current file being examined?
             CString strJustFileName = ????????????????;
         }
    }
}

Thanks
0
DJ_AM_Juicebox
Asked:
DJ_AM_Juicebox
  • 2
1 Solution
 
jkrCommented:
Strip off the path part, i.e.

#include <shlwapi.h> // helper functions by MS
#pragma comment(lib,"shlwapi.lib)

void CMyApp::OnImportMultipleFiles()
{
    CFileDialog cfd(TRUE, ".txt", NULL, OFN_FILEMUSTEXIST | OFN_ALLOWMULTISELECT | OFN_NOCHANGEDIR, strFilters, this, sizeof(OPENFILENAME));

    if (cfd.DoModal() == IDOK) {
        POSITION pos = cfd.GetStartPosition();
        while (pos != NULL) {
             CString strNextPath = cfd.GetNextPathName(pos);

             // How do you get just the file name here of the current file being examined?
             CString strJustFileName = PathFindFileName((LPCTSTR)strNextPath);
         }
    }
}

0
 
jkrCommented:
BTW, you'll find the whole set of the helpers extremely useful: http://msdn2.microsoft.com/en-us/library/ms538767.aspx ("Shell Path Handling Functions")
0
 
DJ_AM_JuiceboxAuthor Commented:
excellent
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now