We take pride in your success. We let our positivity drive us, day in and out. Talk to us at Mindfire to know us more.

Software Technology Tips

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.


Related Tags:

C#, LINQ

Author: Satyadeep Kumar

top

C#

Let us Connect!

privacy

copyright (c) Mindfire Solutions 2007-2012. Login