-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFileWalker.cs
60 lines (56 loc) · 2.05 KB
/
FileWalker.cs
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
using System;
public class FileWalker
{
public static string WalkDirectoryTree(System.IO.DirectoryInfo root, System.IO.DirectoryInfo trueRoot)
{
System.IO.FileInfo[] files = null;
string csv = "";
System.IO.DirectoryInfo[] subDirs = null;
// First, process all the files directly under this folder
try
{
files = root.GetFiles("*.txt");
}
// This is thrown if even one of the files requires permissions greater
// than the application provides.
catch (UnauthorizedAccessException e)
{
// This code just writes out the message and continues to recurse.
// You may decide to do something different here. For example, you
// can try to elevate your privileges and access the file again.
Console.WriteLine(e.Message);
}
catch (System.IO.DirectoryNotFoundException e)
{
Console.WriteLine(e.Message);
}
if (files != null)
{
foreach (System.IO.FileInfo fi in files)
{
//Creates the CSV file.
string csvLine = "";
csvLine += fi.Name.Substring(0, fi.Name.Length - 4);
string seperator = root.FullName.Replace(trueRoot.FullName, "");
seperator = seperator.Replace("\\", ",");
csvLine += seperator;
csvLine += ",";
csvLine += DNA_Analyzer.Analyzer(fi);
csvLine += "\n";
if (DNA_Analyzer.Analyzer(fi) != "Normal")
{
csv += csvLine;
Console.WriteLine(csvLine);
}
}
// Now find all the subdirectories under this directory.
subDirs = root.GetDirectories();
foreach (System.IO.DirectoryInfo dirInfo in subDirs)
{
// Resursive call for each subdirectory.
csv += WalkDirectoryTree(dirInfo, trueRoot);
}
}
return csv;
}
}