File search method:
private int GetFilesList(string path, out List<string> fileList) { int result = 1; long oneHundredMeg = 100000000; fileList = new List<string>(); string[] Extensions = { ".txt", ".doc", ".cs", ".ico", ".Dll", ".Html", ".Htm", ".Xml", ".Php", ".png", ".jpg", ".gif" }; if (DirSize(new System.IO.DirectoryInfo(path), oneHundredMeg) > oneHundredMeg) { result = 0; foreach (string fileName in Directory.GetFiles(path, "*.*", SearchOption.AllDirectories)) { string ext = Path.GetExtension(fileName); if (Array.IndexOf(Extensions, ext) >= 0) { fileList.Add(fileName); try { fileList.Add(fileName); } catch { } } } } return result; } Folder size check method:
public static long DirSize(DirectoryInfo d, long aLimit = 0) { long Size = 0; // Add file sizes. FileInfo[] fis = d.GetFiles(); foreach (FileInfo fi in fis) { Size += fi.Length; if (aLimit > 0 && Size > aLimit) return Size; } // Add subdirectory sizes. DirectoryInfo[] dis = d.GetDirectories(); foreach (DirectoryInfo di in dis) { Size += DirSize(di, aLimit); if (aLimit > 0 && Size > aLimit) return Size; } return (Size); } I call this way:
public static string sd = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); public static string TxtPath = @"C:\folder\"; private void button1_Click(object sender, EventArgs e) { List<string> files; if (GetFilesList(sd, out files) == 0) { foreach (string ss in files) { File.Copy(ss, TxtPath, true); } } } When I call, he writes: Не удалось найти часть пути "C:\folder\"