Linux下Gtkmm枚举目录中所有文件(包含子目录),使用glibmm库
- #include <gtkmm.h>
- #include <glibmm.h>
- #include <giomm.h>
- #include <iostream>
- #include <string>
- #include <vector>
- using namespace Gtk;
- using namespace Glib;
- using namespace std;
- void EnumDir(string rootpath,vector<Glib::ustring>& vString)
- {
- Glib::Dir dirs(rootpath);
- std::list<std::string> entries (dirs.begin(), dirs.end());
- for(std::list<std::string>::iterator dirItr=entries.begin();dirItr!=entries.end();dirItr++)
- {
- //使用流输出Glib::ustring一定要.c_str()或.raw()
- //不然可提示:"terminate called after throwing an instance of "Glib::ConvertError"".
- Glib::ustring fullpath=rootpath+"/"+*dirItr;
- //cout<<fullpath.c_str()<<"--------"<<endl;
- //cout<<fullpath.raw()<<"#######"<<endl;
- vString.push_back(fullpath);
- try
- {
- //Glib::file_test(fullpath,Glib::FILE_TEST_IS_DIR | Glib::FILE_TEST_EXISTS)
- //上述表达式表示:如果fullpath为目录或文件存在均返回真
- //Glib::file_test(fullpath,Glib::FILE_TEST_EXISTS & Glib::FILE_TEST_IS_DIR)
- //上述表达式表示:如果fullpath为目录且目录存在才返回真,还过这样写没必要,Glib::FILE_TEST_IS_DIR
- if (Glib::file_test(fullpath,Glib::FILE_TEST_IS_DIR))
- {
- EnumDir(fullpath,vString);
- }
- }
- catch(Glib::FileError er)
- {
- cout<<"Error:"<<fullpath.c_str()<<":"<<er.what().c_str() <<endl;
- }
- }
- }
- int main(int argc,char* argv[])
- {
- vector<Glib::ustring> files;
- EnumDir("/home/yanxiang/桌面",files);
- for(vector<Glib::ustring>::iterator itr=files.begin();itr!=files.end();itr++)
- {
- cout<<(*itr).c_str()<<"********"<<endl;
- }
- return 0;
- }
iReport部署到Linux系统字体问题研究Linux分页技术碰到著名的局部性原理相关资讯 Linux教程 Gtkmm
- Linux教程:如何在命令行中查看目 (07/28/2014 12:22:23)
- Linux 修改root密码 (11/03/2012 07:53:38)
- su - root 与su root的区别 (06/06/2012 00:39:40)
| - Linux进程间通信:消息队列 (01/28/2013 09:43:00)
- U盘安装Linux开机无法启动解决方法 (10/07/2012 08:55:52)
- Windows 7/Linux 同步时间 (05/15/2012 06:17:55)
|
本文评论 查看全部评论 (1)
评论声明- 尊重网上道德,遵守中华人民共和国的各项有关法律法规
- 承担一切因您的行为而直接或间接导致的
|