wasSharpNET – Blame information for rev 21

Subversion Repositories:
Rev:
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;
8 using System.IO;
9  
10 namespace wasSharpNET.IO.Utilities
11 {
12 public static class IOExtensions
13 {
14 public static bool isRootedIn(this string path, string root)
15 {
16 // Path is empty and root is empty.
17 if (string.IsNullOrEmpty(path) && string.IsNullOrEmpty(root))
18 return true;
19  
20 // Path is empty but the root path is not empty.
21 if (string.IsNullOrEmpty(path) && !string.IsNullOrEmpty(root))
22 return true;
23  
24 // The supplied root path is empty.
25 if (string.IsNullOrEmpty(root))
26 return false;
27  
28 // The path is empty and the root is not.
29 if (string.IsNullOrEmpty(path))
30 return true;
31  
32 DirectoryInfo p = new DirectoryInfo(path);
33 DirectoryInfo r = new DirectoryInfo(root);
34  
35 return string.Equals(p.Parent?.FullName, r.Parent?.FullName) || isRootedIn(p.Parent?.FullName, root);
36 }
37  
38 public static void Empty(this string directory)
39 {
40 DirectoryInfo dir = new DirectoryInfo(directory);
41  
42 foreach (FileInfo fi in dir.GetFiles())
43 {
44 fi.Delete();
45 }
46  
47 foreach (DirectoryInfo di in dir.GetDirectories())
48 {
49 Empty(di.FullName);
50 di.Delete();
51 }
52 }
53 }
54 }