Translate

Tuesday, October 23, 2012

c# search for file in directory

The code below finds all the text files in the directory and the child directories in which the exe resides.


using System; 
using System.IO;
 
namespace FindFiles
{
   class Program
   {
      static void Main(string[] args)
      {
            
         string path = Directory.GetCurrentDirectory();//path to be searched
         string[] textFiles = Directory.GetFiles(path, "*.txt"SearchOption.AllDirectories);
 
 
         foreach (string file in textFiles)
         {
             Console.WriteLine(file);
 
         } 
 
 
      }
   }
}

No comments:

Post a Comment

Comments will appear once they have been approved by the moderator