【发布时间】:2014-02-11 12:54:40
【问题描述】:
说明: 我正在尝试将目录中的所有文件移动到某个(用户选择的目录),基于它们通过 boost 文件系统到某个目录的扩展名。 问题: 当 boost 文件系统的 rename/copy_file 方法被命中时,我收到称为错误的 R6010-Abort 方法。 示例:
SourceDirectory:C:\Source\a.txt
DestinationDirectory:C:\Destination
执行后:
DestinationDirectory:C:\Destination\a.txt
代码:
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include "boost/filesystem/operations.hpp"
#include "boost/filesystem/path.hpp"
#include "boost/progress.hpp"
#include "boost/algorithm/string/regex.hpp"
#include "boost/regex.hpp"
namespace fs = boost::filesystem;
using namespace std;
void categorizeFolder()
{
//Source Folder
std::string folderToCategorize;
cout<<"Choose the folder you want to categorize:";
cin>>folderToCategorize;
cout << "The directory you have choosen is: " << folderToCategorize << endl;
//Destination folder
std::string newfolder;
cout<<"Choose the folder you want to store your files:";
cin>>newfolder;
cout << "The directory you have choosen is: " << newfolder << endl;
std::vector< std::string > all_matching_files;
boost::filesystem::directory_iterator end_itr;
for( boost::filesystem::directory_iterator i( folderToCategorize ); i != end_itr; ++i )
{
if( !boost::filesystem::is_regular_file( i->status() ) ) continue;
if( i->path().extension() == ".txt" )
{
cout<<i->path().extension();//Printing File extension
cout<<i->path();//Printing file path
cout<<i->path().filename()<<endl; //Printing filename
fs::rename(i->path(), newfolder);//This would move the file//Even tried fs::copy_file(i->path(), newfolder)
}
}
}
如果我在上面的代码中遗漏了什么,请告诉我。提前致谢。
问候, 拉维
【问题讨论】: