我试图使用boost :: filesystem :: remove_all(path)从特定路径中删除所有目录,子目录和包含的文件.我还想显示一个错误消息,以防文件在另一个程序中打开.在这种情况下boost :: filesystem :: remove_all(path)会抛出异常吗?
或者还有另一种方法可以达到这个目的吗?
Rem*_*anu 10
这不适合评论,所以我发布作为答案
只需查看源代码:http://www.boost.org/doc/libs/1_55_0/libs/filesystem/src/operations.cpp
BOOST_FILESYSTEM_DECL
boost::uintmax_t remove_all(const path& p, error_code* ec)
{
error_code tmp_ec;
file_type type = query_file_type(p, &tmp_ec);
if (error(type == status_error, tmp_ec, p, ec,
"boost::filesystem::remove_all"))
return 0;
return (type != status_error && type != file_not_found) // exists
? remove_all_aux(p, type, ec)
: 0;
}
Run Code Online (Sandbox Code Playgroud)
remove_all_aux被定义几行以上,所以是remove_file_or_directory,remove_file,remove_directory等等等等.原始操作是:
# if defined(BOOST_POSIX_API)
...
# define BOOST_REMOVE_DIRECTORY(P)(::rmdir(P)== 0)
# define BOOST_DELETE_FILE(P)(::unlink(P)== 0)
...
# else // BOOST_WINDOWS_API
...
# define BOOST_REMOVE_DIRECTORY(P)(::RemoveDirectoryW(P)!= 0)
# define BOOST_DELETE_FILE(P)(::DeleteFileW(P)!= 0)
...
# endif
Run Code Online (Sandbox Code Playgroud)
删除锁定文件的行为将是您的平台将提供的任何内容.