自己写的QuickSearch

4

Comments

今天研究Discuz!代码的时候要搜索一个函数在哪里被调用,结果不懂怎么办。

Windows的搜索貌似某个服务被我禁了一直以来都不能用,而Google的Desktop又不收编这些东西……

花了一点时间写了一个QuickSearch,代码也很短,效率也很高。用法就是“QuickSearch 关键字”。就会遍历当前目录及其子目录下的所有的文件,查找包含关键字的文件。

如果你也喜欢可以在这里下载:QuickSearch.exe (16KB)

由于使用VS2005编译,需要.NET Framework 2.0支持。源代码在下方,可以用VS2003编译。

蛮好用的说,代码也很短:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using System;
using System.IO;
 
namespace QuickSearch
{
    class Program
    {
        static string curdir = Directory.GetCurrentDirectory();
        static int lcurdir = curdir.Length + 1;
        static string searchText;
 
        static void Main(string[] args)
        {
            searchText = args[0];
            SearchDir(curdir);
        }
 
        static string filecontent;
 
        static void SearchDir(string path)
        {
            string[] files = Directory.GetFiles(path);
            foreach (string file in files)
            {
                filecontent = File.ReadAllText(file);
                if (filecontent.IndexOf(searchText) > 0)
                    Console.WriteLine(file.Substring(lcurdir));
            }
            string[] dirs = Directory.GetDirectories(path);
            foreach (string dir in dirs)
                SearchDir(dir);
        }
    }
}

4 Responses to “自己写的QuickSearch”

  1. felix021 Says:
    2009年11月8日 19:05 回复

    我会推荐cygwin + vim + ctags

    • upsuper Says:
      2009年11月8日 20:08 回复

      其实在 Linux 下实现同样的功能只要 find | xargs grep 即可……所以请注意观察日期!

  2. felix021 Says:
    2009年11月8日 23:12 回复

    不是要做开发么,开发的时候还是得用ctags/cscope啊。

    • upsuper Says:
      2009年11月9日 16:31 回复

      暂时没有使用……反正现在的 vim 的自动补全也够我用了……

Leave a Reply