views:

190

answers:

5

I want to get the file name in a given path is there any apis available . My programming environment is vc++ mfc

+3  A: 

You should look at FindFirstFile and FindNextFile, or MFC's wrapper for them, CFileFind.

RichieHindle
A: 

You'll find an implementation here.

luvieere
+1  A: 

You can also use MFC: CFileFind

Naveen
+2  A: 

Boost has a great platform independent filesystem library. It'll work with MFC.

Here's an example from their reference:

#include <iostream>
#include <filesystem>

using std::tr2::sys;
using std::cout;

int main(int argc, char* argv[])
{
  std::string p(argc <= 1 ? "." : argv[1]);

  if (is_directory(p))
  {
    for (directory_iterator itr(p); itr!=directory_iterator(); ++itr)
    {
      cout << itr->path().filename() << ' '; // display filename only
      if (is_regular_file(itr->status())) cout << " [" << file_size(itr->path()) << ']';
      cout << '\n';
    }
  }
  else cout << (exists(p) ? "Found: " : "Not found: ") << p << '\n';

  return 0;
}
Kieveli
A: 

There is also CListBox::Dir. It's very convenient if you want to fill a list box with file names.

Nick D