I wrote the following routine in order to copy all files in a directory to a subdirectory and then remove them, but I keep getting an access denied on the copy_fail which looks misleading to me. Paths are corrects, files exist and permission are not read-only in the destination directory just created.
Any suggestion how to hunt the source of the problem?
I tried to debug, but I don't have the boost::filesystem source code.
Any suggestion is appreciated.
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());
  }
 }
}
You have to specify the filename you want for subdirPath and not just the path. boost's copy_file isn't smart enough to know that by specifying a directory name, you want the file to have the same name as the source.
What OS are running this on? If on Linux/Unix then have you considered permissions on directory holding your source files (you are removing currentConfigurationFile, this means that directory holding that file must have write permission)?
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论