Boost FileSystem 库使用说明2

本文介绍如何使用Boost C++库中的FileSystem组件来获取文件属性,包括判断是否为目录、获取路径、根路径、文件名及扩展名等,并展示了如何遍历指定目录下的所有文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include <boost/filesystem.hpp>
#include <boost/filesystem/operations.hpp>
using namespace boost::filesystem;

 //文件属性

CString strPath=_T("d:\\a.txt");
 wpath p(strPath.GetBuffer());
 bool bIsDirectory=is_directory(p);
 wstring sPath=p.wstring();
 wstring sroot_path=p.root_path().wstring();
 wstring sleaf=p.leaf().wstring();
 wstring sfilename=p.filename().wstring();
 wstring sExtension=p.extension().wstring();
 CString str;
 str.Format(_T("bIsDirectory = %d  \npath= %s \nsExtension= %s \n sroot_path= %s \n sfilename= %s \nsleaf= %s"),
  bIsDirectory,
  sPath.c_str(),
  sExtension.c_str(),
  sroot_path.c_str(),
  sfilename.c_str(),
  sleaf.c_str());
 AfxMessageBox(str);

 

//遍历目录所有文件

 directory_iterator diend;
 for (directory_iterator pos("d:\\");pos!=diend; ++pos)
  {
  wpath p=pos->path();
  wstring s=p.wstring();
  
  CString str;
  str.Format(_T("%s    %d"),s.c_str(),is_directory(p));
  AfxMessageBox(str);
  }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值