簡體   English   中英

Boost:copy_file失敗,訪問被拒絕,但是沒有權限問題

[英]Boost: copy_file fail with access denied but there are no permission problem

我編寫了以下例程,以便將目錄中的所有文件復制到子目錄中,然后將其刪除,但是我不斷獲得對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不夠聰明,無法知道通過指定目錄名稱來使文件與源具有相同的名稱。

在什么操作系統上運行它? 如果在Linux / Unix上,您是否考慮過保存源文件的目錄的權限(要刪除currentConfigurationFile,這意味着保存該文件的目錄必須具有寫權限)?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM