Format partitions by emptying the contents rather than deleting the folder

This commit is contained in:
Luke Usher 2018-02-24 18:19:35 +00:00
parent b459843c80
commit b0cdc4891a
1 changed files with 6 additions and 6 deletions

View File

@ -184,14 +184,14 @@ void CxbxFormatPartitionByHandle(HANDLE hFile)
return; return;
} }
// Format the partition, by deleting it's folder and re-creating it
// In this case, experimental means that these functions work and are safe // Format the partition, by iterating through the contents and removing all files/folders within
// but not officially in the C++ standard yet // Previously, we deleted and re-created the folder, but that caused permission issues for some users
// Requires a compiler with C++17 support
try try
{ {
std::experimental::filesystem::remove_all(partitionPath); for (auto& directoryEntry : std::experimental::filesystem::recursive_directory_iterator(partitionPath)) {
std::experimental::filesystem::create_directory(partitionPath); std::experimental::filesystem::remove_all(directoryEntry);
}
} }
catch (std::experimental::filesystem::filesystem_error fsException) catch (std::experimental::filesystem::filesystem_error fsException)
{ {