forked from microsoft/PullRequestQuantifier
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileSystemExtensions.cs
More file actions
50 lines (45 loc) · 1.42 KB
/
FileSystemExtensions.cs
File metadata and controls
50 lines (45 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
namespace PullRequestQuantifier.Common.Extensions
{
using System.IO;
using System.IO.Abstractions;
using System.Linq;
public static class FileSystemExtensions
{
public static void DeleteDirectory(this IFileSystem fileSystem, string path)
{
#pragma warning disable CS0618 // Do not catch general exception types
var dirInfo = fileSystem.DirectoryInfo.New(path);
#pragma warning restore CS0618 // Do not catch general exception types
if (dirInfo.Exists)
{
try
{
SetNormalAttribute(dirInfo);
dirInfo.Delete(true);
}
#pragma warning disable CA1031 // Do not catch general exception types
catch
#pragma warning restore CA1031 // Do not catch general exception types
{
}
}
}
private static void SetNormalAttribute(IDirectoryInfo dirInfo)
{
if (!dirInfo.Exists)
{
return;
}
var directories = dirInfo.GetDirectories().ToArray();
foreach (var subDir in directories)
{
SetNormalAttribute(subDir);
}
var files = dirInfo.GetFiles().ToArray();
foreach (var file in files)
{
file.Attributes = FileAttributes.Normal;
}
}
}
}