emi*_*rax 2 c++ boost-filesystem
我编写了以下例程,以便将目录中的所有文件复制到子目录然后将其删除,但我仍然在copy_fail上获得访问被拒绝,这看起来很容易让我误解.路径是更正,文件存在,并且权限在刚刚创建的目标目录中不是只读的.
有什么建议如何寻找问题的根源?
我试图调试,但我没有boost :: filesystem源代码.
任何建议表示赞赏.
void
moveConfigurationFileToSubDirectory()
{
// TODO: Catch errors.
boost::filesystem::path full_path( boost::filesystem::current_path() );
// Create directory subdir if not exist
boost::filesystem::path subdirPath(kSubdirectory);
if ( !boost::filesystem::exists(subdirPath) )
{
PLog::DEV.Development(devVerbose, "%s: creating directory %s", __FUNCTION__, subdirPath.string());
boost::filesystem::create_directories(subdirPath);
} else
PLog::DEV.Development(devVerbose, "%s: directory %s exist", __FUNCTION__, subdirPath.string());
// Iterate through the configuration files defined in the static array
// copy all files with overwrite flag, if successfully delete file (looks like there is not remove)
for (int i = 0; i < kNumberOfConfigurationFiles; i++)
{
boost::filesystem::path currentConfigurationFile(kConfigurationFiles[i]);
try
{
boost::filesystem::copy_file(currentConfigurationFile, subdirPath, boost::filesystem::copy_option::overwrite_if_exists);
boost::filesystem::remove(currentConfigurationFile);
}
catch (exception& e)
{
PLog::DEV.Development(devError, "%s: exception - %s", __FUNCTION__, e.what());
}
}
}
Run Code Online (Sandbox Code Playgroud)
您必须为subdirPath指定所需的文件名,而不仅仅是路径.boost的copy_file不够聪明,不知道通过指定目录名,您希望文件与源名称相同.
| 归档时间: |
|
| 查看次数: |
3740 次 |
| 最近记录: |