Repository navigation
Expand file tree
/
Copy pathFileSystem.cs
More file actions
80 lines (69 loc) · 2.09 KB
/
Copy pathFileSystem.cs
File metadata and controls
80 lines (69 loc) · 2.09 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
namespace NAppUpdate.Framework.Utils
{
public static class FileSystem
{
public static void CreateDirectoryStructure(string path)
{
CreateDirectoryStructure(path, true);
}
public static void CreateDirectoryStructure(string path, bool pathIncludeFile)
{
string[] paths = path.Split(Path.DirectorySeparatorChar);
// ignore the last split because its the filename
int loopCount = paths.Length;
if (pathIncludeFile)
loopCount--;
for (int ix = 0; ix < loopCount; ix++)
{
string newPath = paths[0] + @"\";
for (int add = 1; add <= ix; add++)
newPath = Path.Combine(newPath, paths[add]);
if (!Directory.Exists(newPath))
Directory.CreateDirectory(newPath);
}
}
/// <summary>
/// Safely delete a folder recuresively
/// See http://stackoverflow.com/questions/329355/cannot-delete-directory-with-directory-deletepath-true/329502#329502
/// </summary>
/// <param name="targetDir">Folder path to delete</param>
public static void DeleteDirectory(string targetDir)
{
string[] files = Directory.GetFiles(targetDir);
string[] dirs = Directory.GetDirectories(targetDir);
foreach (string file in files)
{
File.SetAttributes(file, FileAttributes.Normal);
File.Delete(file);
}
foreach (string dir in dirs)
{
DeleteDirectory(dir);
}
File.SetAttributes(targetDir, FileAttributes.Normal);
Directory.Delete(targetDir, false);
}
public static IEnumerable<string> GetFiles(string path, string searchPattern, SearchOption searchOption)
{
string[] searchPatterns = searchPattern.Split('|');
var files = new List<string>();
foreach (string sp in searchPatterns)
files.AddRange(System.IO.Directory.GetFiles(path, sp, searchOption));
return files;
}
public static bool IsExeRunning(string path)
{
var processes = Process.GetProcesses();
foreach (Process p in processes)
{
if (p.MainModule.FileName.StartsWith(path, StringComparison.InvariantCultureIgnoreCase))
return true;
}
return false;
}
}
}