-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFileHandler.cs
More file actions
68 lines (54 loc) · 1.5 KB
/
FileHandler.cs
File metadata and controls
68 lines (54 loc) · 1.5 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
using System;
using System.Collections.Generic;
using System.IO;
namespace SimpleDocs
{
public class FileHandler
{
public static string[] GetFiles(string dir, string fileType, bool recursively)
{
List<string> files = new List<string>();
getFilesRecursively(dir, fileType, files, recursively);
return files.ToArray();
}
private static void getFilesRecursively(string dir, string fileType, List<string> files, bool recursively)
{
if (fileType == null || fileType == "")
{
files.AddRange(Directory.GetFiles(dir));
}
else
{
string[] containedFiles = Directory.GetFiles(dir);
foreach (string file in containedFiles)
{
if (file.ToLower().EndsWith(fileType) == false)
continue;
files.Add(file);
}
}
if (recursively == false)
return;
string[] subdirs = Directory.GetDirectories(dir);
foreach (string subdir in subdirs)
getFilesRecursively(subdir, fileType, files, recursively);
}
public static string GetCommentsFromFile(string file)
{
TextReader reader = new StreamReader(file);
string content = reader.ReadToEnd();
reader.Close();
string[] lines = content.Replace("\r", "").Split(new char[] { '\n' });
string comment;
string comments = "";
foreach (string line in lines)
{
comment = line.Trim();
if (comment.StartsWith("///") == false)
continue;
comments += (comments != "" ? "\n" : "") + comment.Substring(3).Trim();
}
return comments;
}
}
}