The following code can be used to extract files that are greater than 1MB under any specific directory (using LINQ).
private static void GetFiles(string Path) { try { DirectoryInfo directory = new DirectoryInfo(Path); FileInfo[] files = directory.GetFiles("*.*", SearchOption.AllDirectories); var query = from file in files where file.Length > 1024*1024 select "File Name:"+ file.Name + " File Size: " + file.Length.ToString(); foreach (string str in query) { Console.WriteLine(str); } } catch (Exception ex) { Console.WriteLine(ex.Message); } }
– Call the above defined function in Main() like
GetFiles(@”E:\books”);
It will return all files that are greater than 1 MB.