代码是咒语,我是魔法师
posted on 2006-12-13 00:29 橙子 阅读(6031) 评论(3) 编辑 收藏 引用 所属分类: C++ & STL
我也刚学这个 贴个自己的例子 #include <iostream> #include <string> #include <ctime> #pragma warning(push) #pragma warning(disable:4819) #pragma warning(disable:4996) #include <boost/filesystem/path.hpp> #include <boost/filesystem/operations.hpp> #include <boost/filesystem.hpp> #pragma warning(pop) using namespace std; using namespace boost; namespace fs = boost::filesystem; void RecusiveListFiles(fs::path& fpath) { fs::recursive_directory_iterator beg_iter(fpath); fs::recursive_directory_iterator end_iter; for (; beg_iter != end_iter; ++beg_iter) { if (fs::is_directory(*beg_iter)) { continue; } else { cout<<beg_iter->path().file_string()<<'\n'; time_t t = fs::last_write_time(*beg_iter); cout<<ctime(&t); uintmax_t filesize = fs::file_size(*beg_iter); cout<<filesize<<"\n\n"; } } } int main(int argc, char* argv[]) { try { if (argc < 2) { cout<<"Invalid arg --- You should input a Directory path as an argument.(ex: c:\\DELL)\n"; return -1; } RecusiveListFiles(fs::path(string(argv[1]), fs::native)); } catch (exception& e) { cout<<e.what()<<endl; } return 0; } 回复 更多评论
fs::directory_iterator item_end; 为何不需初始化? 回复 更多评论
你确定这代码能跑编过? 回复 更多评论
Powered by: C++博客 Copyright © 橙子