1 """findgremlins - Search through a folder and subfolders for
2 text files that have characters with bit 8 set, and print
3 the filename and a bit of context.
5 By Just, with a little glue by Jack"""
13 xpat
= re
.compile(r
"[\200-\377]")
15 def walk(top
, recurse
=1):
16 if os
.path
.isdir(top
):
18 for name
in os
.listdir(top
):
19 path
= os
.path
.join(top
, name
)
22 cr
, tp
= macfs
.FSSpec(top
).GetCreatorType()
23 if tp
== 'TEXT' and top
[-4:] <> ".hqx":
24 data
= open(top
).read()
27 if ord(ch
) == 0 or ord(ch
) >= 0200:
28 badcount
= badcount
+ 1
30 print `top`
, 'appears to be a binary file'
35 m
= xpat
.search(data
, pos
)
42 print " ", string
.replace(data
[i
-15:j
+15], '\n', ' ')
46 fss
, ok
= macfs
.GetDirectory()
48 walk(fss
.as_pathname())
50 if __name__
== '__main__':
52 sys
.exit(1) # So we see the output