Saturday, October 11, 2008

WinGrep - a simple Windows grep-like console application

Windows search tool wasn't enough to find the methods I was looking for, inside .jad files. So I wrote a few lines of C# code to have this explendid tool. It behaves like Linux grep, except for its regular expressions, lol.

http://jaderd.googlepages.com/WinGrep.exe

Arguments:
1: start folder path (e.g.: c:\)
2: file pattern (e.g.: *.class)
3: search string (e.g.: getFromLocation)

Full example : WinGrep.exe c:\ *.class getFromLocation

3 comments:

Anonymous said...

Can you please share the code?

Anonymous said...

Can you please share the code?

Jader Dias said...

private static void Main(string[] args)
{
if (args.Length < 3)
{
args = new string[3];
Console.Write("program: ");
args[0] = Console.ReadLine();
Console.Write("file pattern: ");
args[1] = Console.ReadLine();
Console.Write("search string: ");
args[2] = Console.ReadLine();
}
foreach (string str in Directory.GetFiles(args[0], args[1], SearchOption.AllDirectories))
{
using (StreamReader reader = new StreamReader(str))
{
string str2;
for (int i = 1; (str2 = reader.ReadLine()) != null; i++)
{
if (str2.Contains(args[2]))
{
Console.WriteLine(str + ": " + i);
}
}
}
}
Console.ReadLine();
}