Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.85 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. namespace FileSearcher {
  4.     class Program {
  5.         static void Main( string[] args ) {
  6.             if(args.Length != 2) {
  7.                 Console.WriteLine("Error: usage is FileSearcher Directory String");
  8.                 return;
  9.             }
  10.             string[] filesToSearch = Directory.GetFiles(@args[0], "*.cs", SearchOption.AllDirectories);
  11.             string line;
  12.             foreach (string filePath in filesToSearch) {
  13.                 using (StreamReader file = new StreamReader(filePath)) {
  14.                     int lineCount = 1;
  15.                     while((line = file.ReadLine()) != null) {
  16.                         if (line.Contains(args[1])) Console.WriteLine(filePath + " @Line " + lineCount);
  17.                         lineCount++;
  18.                     }
  19.                 }
  20.             }
  21.         }
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement