Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //*****************************************************************************
- // Вспомогательный класс, дополняющий DirectoryInfo(инфу каталога...)
- // методом GetAllFiles который выдаёт спикок FileInfo
- // тобишь информацию о всех файлах в каталоге.
- //
- // Использовать примерно так:
- // using System.IO;
- // using Progolab.Extentions;
- // DirectoryInfo di = new DirectoryInfo("C:\\SomeDirectory\\");
- // List<FileInfo> all_files = di.GetAllFiles();
- // foreach (FileInfo fi in all_files)
- // {
- // Console.WriteLine(fi.FullName);
- // }
- //
- // PS: Финчи шарпа 3.0, чтоб использовать нужен Framework 3.0+
- // PPS: Have fun =)
- // PPPS: CollectFiles написанна на земном C# 1.0 =)...
- //*****************************************************************************
- namespace Progolab.Extentions
- {
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.IO;
- public static class DirectoryInfoExtention
- {
- /// <summary>
- /// Список ВСЕХ файлов в пределах директории
- /// </summary>
- /// <param name="dir">Указатель на директорию в которой ищем</param>
- /// <returns>Список ВСЕХ файлов в пределах директории</returns>
- public static List<FileInfo> GetAllFiles(this DirectoryInfo dir)
- {
- //Готовим список
- List<FileInfo> fileList = new List<FileInfo>();
- //Вызов хитрой вспомогательной функции
- CollectFiles(dir.FullName, fileList);
- //Что собрали то и выплёвываем
- return fileList;
- }
- /// <summary>
- /// Собираем все файлы в текущей директории
- /// </summary>
- /// <param name="curr_path">Каталог в котором ищем</param>
- /// <param name="fileList">Список в который всё собираем</param>
- static void CollectFiles(string curr_path, List<FileInfo> fileList)
- {
- //Рекурсивно "падаем" в каждую из директорий текущего каталога
- foreach (string dir_name in Directory.GetDirectories(curr_path))
- CollectFiles(dir_name + "\\", fileList);
- //Собираем все файлы в текущем каталоге
- foreach (string file_name in Directory.GetFiles(curr_path))
- fileList.Add(new FileInfo(file_name));
- }
- }
- }
Add Comment
Please, Sign In to add comment