Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.3 kB
5
Indexable
Never
using System;
using System.IO;

namespace FindTxtOnDisk
{
     class Program
     {
          // UNETI ISPOD PUT DO FOLDERA
          static readonly string rootFolder = "D:\\school\\treca godina\\studentski radovi 2021 - laboratorijske vezbe";
          // UNETI ISPOD TRAZENI STRING
          static readonly string searchString = "racunarskog kluba";

          static void Main(string[] args)
          {

               DirectoryInfo d = new DirectoryInfo(rootFolder); 
               DirectoryInfo[] Directories = d.GetDirectories();
               string str = "";
               string text;

               foreach (DirectoryInfo file in Directories)
               {
                    str = file.Name;
                    DirectoryInfo directoryInfo = new DirectoryInfo(rootFolder + "\\" + str);
                    FileInfo[] Files = directoryInfo.GetFiles("*.txt");
                    if (Files != null)
                    {
                         text = File.ReadAllText(directoryInfo.FullName + "\\" + Files[0].Name);
                         if (text.Contains(searchString))
                              Console.WriteLine(directoryInfo.FullName);
                    }                 
               }
               Console.WriteLine(str);
          }
     }
}