02-21-2010, 02:49 PM
(This post was last modified: 02-21-2010, 02:55 PM by jurank_dankkal.)
PHP Code:
#!/usr/bin/env python
import sys
import os
def find_file(tree, pattern, func):
try:
listdir=os.list(tree)
except:
func(tree, '(error)')
return
#
for i in listdir:
path=os.path.join(tree, i)
#
if os.path.isdir(path)
find_file(path, pattern, func) #recursion
#
if pattern in i:
func(path)
def file_found_simple(file_name, message=''):
print '%s%s' %(message, file name)
if _name_=='_main_':
try:
tree=sys.argv[1]
pattern=sys.argv[2]
except:
print '%s<tree><pattern>' %(sys.argv[0])
sys.exit(1)
#
try:
test=os.listdir(tree)
except Exception, e:
print e
sys.exit(2)
#
find_file(tree, pattern, file_found_simple)
bwt linux kk.





