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
|
public class ListFiles
{
/// <summary>
/// Creates a list which contains all filenames in a specific folder
/// </summary>
/// <param name="Root">Folder which contains files to be listed</param>
/// <param name="SubFolders">True for scanning subfolders</param>
/// <returns></returns>
public List<string> GetFileList(string Root, bool SubFolders)
{
List<string> FileArray = new List<string>();
try {
string[] Files = System.IO.Directory.GetFiles(Root);
string[] Folders = System.IO.Directory.GetDirectories(Root);
for (int i = 0; i < Files.Length; i++)
{
FileArray.Add(Files[i].ToString());
}
if (SubFolders == true)
{
for (int i = 0; i < Folders.Length; i++)
{
FileArray.AddRange(GetFileList(Folders[i], SubFolders));
}
}
}
catch (Exception Ex)
{
throw (Ex);
}
return FileArray;
}
}
|