- 论坛徽章:
- 0
|
- # -*- coding:gbk -*-
- # file name findmyfile.py
- import sys,os,fnmatch
- def deepthfind(rootdir,writefile,patterns=''):
- endline = "\n";
- if writefile.endswith("html") or writefile.endswith("htm"):
- endline = "<br>";
- file_object = open(writefile, 'w')
- print "*** Searching ... "
-
- for path, subdirs, files in os.walk(rootdir):
- iswritepath = 1
- for name in files:
- fullname = path + os.sep +name
- if name.find(patterns)!=-1:
- if iswritepath:
- file_object.write("<b>"+path +"</b>"+ endline)
- iswritepath = 0
- file_object.write(name + endline)
- print "*** Done ! "
- file_object.close()
- if len(sys.argv) < 2:
- print "Usage : thisfile dir keywords"
- if len(sys.argv) == 2:
- deepthfind(sys.argv[1])
- if len(sys.argv) == 3:
- deepthfind(sys.argv[1],sys.argv[2])
- if len(sys.argv) == 4:
- deepthfind(sys.argv[1],sys.argv[2],sys.argv[3])
复制代码
example:
c:\>findmyfile.py D:\\书籍 c:\\record.html .chm
==============
2006-04-18 改版 谢谢wolfg !
[ 本帖最后由 九佰 于 2006-4-18 10:58 编辑 ] |
|