C++用boost库操作a目录下文件改名生成到b目录下

记录一下,这是本人写的第一篇csdn博客,以后会逐渐趋于规范。

//能加const的尽量加上,慢慢培养成的一种习惯。
const boost::filesystem::path& fileDir = "G:\\work\\model\\Ogf\\source\\ogf";

//不需要初始化,directory_iterator类默认构造的iterator就是指向end的。
const boost::filesystem::directory_iterator end_iter;

	boost::filesystem::directory_iterator iter(fileDir);
	for (iter; iter != end_iter; ++iter)
	{
		if (boost::filesystem::is_regular_file(iter->status()))
		{
			static int i = 1;
			auto toPath = "G:\\A\\B\\" + std::to_string(i++);
			
			//rename到新的path,旧的path下的文件将被删除。
			boost::filesystem::rename(iter->path(), toPath);	
		}
	}
发布了21 篇原创文章 · 获赞 3 · 访问量 617

猜你喜欢

转载自blog.csdn.net/W96866/article/details/105600085