This is my code so far:
import os
class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
user_input = input('What is the name of your directory')
directory = os.listdir(user_input)
searchstring = "import os"
for fname in directory:
if os.path.isfile(user_input + os.sep + fname):
# Full path
f = open(user_input + os.sep + fname, 'r')
if searchstring in f.read():
print(bcolors.OKGREEN + '[-]' + bcolors.ENDC + 'String found in file' % fname )
else:
print(bcolors.FAIL + '[+]' + bcolors.ENDC + 'String not found in file %s' %fname)
f.close()
Im trying to see the error...I'm not sure. My goal is for this to find a string. Why do i get this:
Traceback (most recent call last):
File "/Users/jl/Downloads/Simple-Adware-master/src/adware/findstring.py", line 23, in <module>
if searchstring in f.read():
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/codecs.py", line 322, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 3131: invalid start byte
I don't know how and why I get this error. Any ideas? It'll be appreciated. Credit to Kenly for posting the code :)