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
2009-11-12 13:27:31
+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
2009-11-12 13:31:09
A:
There is also CListBox::Dir. It's very convenient if you want to fill a list box with file names.
Nick D
2009-11-12 13:47:03