2

ディレクトリ内のすべてのファイルをサブディレクトリにコピーしてから削除するために、次のルーチンを作成しましたが、誤解を招くように見える 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());
  }
 }
}
4

2 に答える 2

7

パスだけでなく、subdirPathに必要なファイル名を指定する必要があります。boostのcopy_fileは、ディレクトリ名を指定することにより、ファイルにソースと同じ名前を付けたいことを知るのに十分なほど賢くはありません。

于 2012-12-10T20:09:03.127 に答える
0

これを実行しているOSは何ですか?Linux/Unix の場合、ソース ファイルを保持しているディレクトリのアクセス許可を考慮しましたか (currentConfigurationFile を削除しています。つまり、そのファイルを保持しているディレクトリには書き込みアクセス許可が必要です)。

于 2010-11-17T18:18:40.790 に答える