エラー処理とかしてないけど、とりあえずこれでよし。
#include <iostream> #include <boost/filesystem/operations.hpp> #include <boost/filesystem/path.hpp> #include <boost/filesystem/fstream.hpp> using namespace std; using namespace boost::filesystem; int main(void) { path fullPath = complete(path("/Users/yasuhisa/dbcls/pne/year", native)); directory_iterator end; for (directory_iterator it(fullPath); it !=end; ++it){ cout << it->leaf() << endl; } return 0; }
コンパイルの時に注意が必要。
/tmp% g++ -l boost_system-xgcc40-mt -l boost_filesystem-xgcc40-mt file.cpp /tmp% ./a.out 1985.txt 1986.txt 1987.txt 1988.txt 1989.txt 1990.txt 1991.txt 1992.txt 1993.txt 1994.txt 1995.txt 1996.txt 1997.txt 1998.txt 1999.txt 2000.txt 2001.txt 2002.txt 2003.txt 2004.txt 2005.txt 2006.txt