Created
December 22, 2009 05:19
-
-
Save kuenishi/261521 to your computer and use it in GitHub Desktop.
an easy desktop search script for windows - simple filename-matching-with-keywords index (LICENSE: MIT)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# index-generation script for search.py - an easy desktop search script | |
import sys, os, re, pickle, stat | |
pfile = "_filelist.pkl" | |
path_separator = "\\" | |
#class File: | |
# def __init__(self, path, filename): | |
# self.path = path | |
# self.filename = filename | |
# try: | |
# os.stat(path + path_separator + filename) | |
# except: | |
# pass | |
# def get_keywords(): | |
# return [self.path, self.filename] | |
def get_keywords(filename, path): | |
# s = os.stat(path+filename) | |
# print path + path_separator + filename | |
return [path, filename] | |
def make_new_list(): | |
names = {} | |
for root, dirs, files in os.walk("."+path_separator): | |
names[root] = [root] | |
for dir in dirs: names[dir] = [dir] | |
for file in files: | |
for keyword in get_keywords(file, root): | |
if not keyword in names: names[keyword] = [] | |
names[keyword].append( root + path_separator + file ) | |
return names | |
def main(): | |
names = make_new_list() | |
pickle.dump(names, open(pfile, 'wb'), -1) | |
print "index dumped on %s." % pfile | |
if __name__ == '__main__': | |
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# an easy desktop search script for windows - simple filename-matching-with-keywords index | |
import sys, os, re, pickle, stat | |
pfile = "_filelist.pkl" | |
path_separator = "\\" | |
def load_list(): | |
try: | |
names = pickle.load(open(pfile, 'rb')) | |
return names | |
except: | |
sys.stderr.write("no index, do index.py\n") | |
raise | |
def main(argv): | |
names = load_list() | |
for (keyword, paths) in names.iteritems(): | |
for searchee in argv[1:]: | |
if keyword.find( searchee ) > 0: | |
for path in paths: print path | |
if __name__ == '__main__': | |
main(sys.argv) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment