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
DJ_AM_JuiceboxAsked:
Who is Participating?
 
jkrConnect With a Mentor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.