2014年01月16日 星期四 16:30
Poco的File模块是C++标准库的补充,其提供了针对文件基本信息和针对文件夹的基本操作,这些操作在C++标准库是缺失的。
代码示例:
#include <Poco/File.h> #include <iostream> #include <string> #include <vector> using namespace std; using namespace Poco; int main(int argc, char** argv) { string path("/etc/hosts"); File file(path); cout << "file path: " << file.path() << endl; cout << "file exists ? " << file.exists() << endl; cout << "can read ? " << file.canRead() << endl; cout << "can wirte ? " << file.canWrite() << endl; cout << "can execute? " << file.canExecute() << endl; cout << "is file ? " << file.isFile() << endl; cout << "is link ? " << file.isLink() << endl; cout << "is directory ? " << file.isDirectory() << endl; cout << "is device ? " << file.isDevice() << endl; cout << "is hidden ? " << file.isHidden() << endl; cout << "created at : " << file.created().epochTime() << endl; cout << "file size: " << file.getSize() << endl; string dirpath("/tmp/a/b/c/d/e"); File dir(dirpath); dir.createDirectories(); file.copyTo(dirpath); vector<string> files; dir.list(files); vector<string>::iterator it; for(it=files.begin();it!=files.end();it++){ cout << "file in dir: " << *it << endl; } dir.remove(true); return 0; }
参考资料:
/usr/include/Poco/File.h
Zeuux © 2024
京ICP备05028076号