#include<boost/filesystem.hpp>
using namespace filesystem;
path类
system_complete();返回绝对路径
string():返回标准格式的路径表示;
dirrectory_string();返回文件系统的格式路径表示;
parent_path():父路径
stem();不带扩展的全路径名字
filename();返回文件名
extension():返回文件扩展名
relative_path();返回相对路径
remove_filename();删除路径中的文件名
replace_extension();可以变更扩展名字
file_status类:
type() ;获取文件的状态
file_not_found:文件不存在
status_unknow:文件存在但状态不知
regular_file:普通文件
directory_file:目录
synlink_file:链接文件
block_file:块设备
character_file:字符设备
fifo_file:管道文件
socket_file:sockket文件
type_unknown:文件类型未知
current_path():返回当前工作路径
file_size():返回文件大小
lase_write_time():最后修改时间
create_directory():创建目录
rename():重命名
remove():删除文件
copy_file(): 文件拷贝
目录迭代:
directory_iterator
directory_iterator end;
for (directory_iterator it("D:/data");it!=end;it++){
*it;
*it.path();//返回路径
}
#include<boost/filesystem.hpp>
using namespace boost;
using namespace std;
void filesystem_test() {
filesystem::path path("D:\\test");
path /= "ConsoleApplication1";
cout << path.filename() << endl;
cout << path.relative_path() << endl;
filesystem::directory_iterator end;
for (filesystem::directory_iterator it(path); it != end; it++) {
cout << *it << endl;
}
path /= "Debug";
cout << path.string() << endl;
cout << filesystem::current_path() << endl;;
for (filesystem::directory_iterator it(path); it != end; it++)
{
if(filesystem::is_regular(it->path()))
cout << it->path() <<"="<< filesystem::file_size((it->path()))/1024.0/1024.0<< endl;
else {
cout << "directory:" << it->path().string() << endl;
}
}
path.append("\\cheji1a\\jiajia1");
cout << "path1" << path << endl;
if(!filesystem::exists(path))
filesystem::create_directories(path);
else{
cout << "path is exists...." << endl;
}
}