c++ - 提升 : copy_file fail with access denied but there are no permission problem

标签 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());
  }
 }
}

最佳答案

您必须为 subdirPath 指定您想要的文件名,而不仅仅是路径。 boost 的 copy_file 不够智能,无法通过指定目录名称知道您希望文件与源同名。

关于c++ - 提升 : copy_file fail with access denied but there are no permission problem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4203431/

相关文章:

boost last_write_time 回到一小时

c++11 - boost::filesystem::current_path() 返回空路径

c++ - 来自文件夹而不是 MSI 的 Windows 应用商店部署文件

c++ - 来自 DDX_CBIndex( ) 的错误值

c++ - 如何使用 boost 图库广度优先搜索创建遍历顶点的队列?

c++ - 使用 boost::filesystem 3.0 迭代文件

C++/boost : checking process permission

c++ - 将数字添加到 ListView

c++ - MATLAB CUDA 内核对象 - 使用收集时出错?

C++ BOOST undefined reference `boost::filesystem::detail::copy_file