wasSharpNET – Blame information for rev 22
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
21 | office | 1 | /////////////////////////////////////////////////////////////////////////// |
2 | // Copyright (C) Wizardry and Steamworks 2017 - License: GNU GPLv3 // |
||
3 | // Please see: http://www.gnu.org/licenses/gpl.html for legal details, // |
||
4 | // rights of fair usage, the disclaimer and warranty conditions. // |
||
5 | /////////////////////////////////////////////////////////////////////////// |
||
6 | |||
7 | using System.IO; |
||
8 | |||
9 | namespace wasSharpNET.IO.Utilities |
||
10 | { |
||
11 | public static class IOExtensions |
||
12 | { |
||
13 | public static bool isRootedIn(this string path, string root) |
||
14 | { |
||
15 | // Path is empty and root is empty. |
||
16 | if (string.IsNullOrEmpty(path) && string.IsNullOrEmpty(root)) |
||
17 | return true; |
||
18 | |||
19 | // Path is empty but the root path is not empty. |
||
20 | if (string.IsNullOrEmpty(path) && !string.IsNullOrEmpty(root)) |
||
21 | return true; |
||
22 | |||
23 | // The supplied root path is empty. |
||
24 | if (string.IsNullOrEmpty(root)) |
||
25 | return false; |
||
26 | |||
27 | // The path is empty and the root is not. |
||
28 | if (string.IsNullOrEmpty(path)) |
||
29 | return true; |
||
30 | |||
31 | DirectoryInfo p = new DirectoryInfo(path); |
||
32 | DirectoryInfo r = new DirectoryInfo(root); |
||
33 | |||
34 | return string.Equals(p.Parent?.FullName, r.Parent?.FullName) || isRootedIn(p.Parent?.FullName, root); |
||
35 | } |
||
36 | |||
37 | public static void Empty(this string directory) |
||
38 | { |
||
39 | DirectoryInfo dir = new DirectoryInfo(directory); |
||
40 | |||
41 | foreach (FileInfo fi in dir.GetFiles()) |
||
42 | { |
||
43 | fi.Delete(); |
||
44 | } |
||
45 | |||
46 | foreach (DirectoryInfo di in dir.GetDirectories()) |
||
47 | { |
||
48 | Empty(di.FullName); |
||
49 | di.Delete(); |
||
50 | } |
||
51 | } |
||
52 | } |
||
53 | } |