mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[DatFile, FileTypes/, Utilities] GUID, but correct
This commit is contained in:
@@ -1775,6 +1775,33 @@ namespace SabreTools.Library.Tools
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Try to safely delete a directory, optionally throwing the error
|
||||
/// </summary>
|
||||
/// <param name="file">Name of the directory to delete</param>
|
||||
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
|
||||
/// <returns>True if the file didn't exist or could be deleted, false otherwise</returns>
|
||||
public static bool TryCreateDirectory(string file, bool throwOnError = false)
|
||||
{
|
||||
// Now wrap creating the directory
|
||||
try
|
||||
{
|
||||
Directory.CreateDirectory(file);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (throwOnError)
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Try to safely delete a directory, optionally throwing the error
|
||||
/// </summary>
|
||||
@@ -1783,13 +1810,13 @@ namespace SabreTools.Library.Tools
|
||||
/// <returns>True if the file didn't exist or could be deleted, false otherwise</returns>
|
||||
public static bool TryDeleteDirectory(string file, bool throwOnError = false)
|
||||
{
|
||||
// Check if the file exists first
|
||||
// Check if the directory exists first
|
||||
if (!Directory.Exists(file))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Now wrap deleting the file
|
||||
// Now wrap deleting the directory
|
||||
try
|
||||
{
|
||||
Directory.Delete(file, true);
|
||||
|
||||
Reference in New Issue
Block a user