C++ Boost:copy_文件失败,访问被拒绝,但没有权限问题
为了将目录中的所有文件复制到子目录,我编写了以下例程 然后删除它们,但我一直拒绝对副本的访问,这对我来说似乎有误导性。在刚刚创建的目标目录中,路径正确,文件存在,权限不是只读的 有没有关于如何找出问题根源的建议 我试图调试,但没有boost::filesystem源代码 如有任何建议,我们将不胜感激C++ Boost:copy_文件失败,访问被拒绝,但没有权限问题,c++,boost-filesystem,C++,Boost Filesystem,为了将目录中的所有文件复制到子目录,我编写了以下例程 然后删除它们,但我一直拒绝对副本的访问,这对我来说似乎有误导性。在刚刚创建的目标目录中,路径正确,文件存在,权限不是只读的 有没有关于如何找出问题根源的建议 我试图调试,但没有boost::filesystem源代码 如有任何建议,我们将不胜感激 void moveConfigurationFileToSubDirectory() { // TODO: Catch errors. boost::filesystem::path full
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());
}
}
}
void
moveConfigurationFileToSubDirectory()
{
//TODO:捕捉错误。
boost::filesystem::path full_path(boost::filesystem::current_path());
//创建目录子目录(如果不存在)
boost::filesystem::path子路径(kSubdirectory);
如果(!boost::filesystem::存在(子路径))
{
PLog::DEV.Development(devVerbose,“%s:创建目录%s”、_函数、子路径.string());
boost::filesystem::创建目录(subdirPath);
}否则
PLog::DEV.Development(devVerbose,“%s:目录%s存在”,_函数,子路径.string());
//遍历静态数组中定义的配置文件
//复制带有覆盖标志的所有文件,如果成功删除文件(看起来没有删除)
对于(int i=0;i
在什么操作系统上运行此功能?如果在Linux/Unix上,那么您是否考虑过对保存源文件的目录的权限(您正在删除currentConfigurationFile,这意味着保存该文件的目录必须具有写入权限)?您必须为子路径指定所需的文件名,而不仅仅是路径。boost的copy_文件不够智能,无法知道通过指定目录名,您希望该文件与源文件具有相同的名称。我在windows上。我使用WindowsAPI重写了相同的功能,它可以正常工作。目标参数需要是文件还是目录?谢谢。为什么不把这个标记为答案?帮了我很多忙,谢谢;)