I made a simple script in python 3 that enters in some folders (all called "recup_dir.x", x stays for a number from 1 to 777) and searches for files containing "firefox" word. Since the files are so much and the process will take much long, I decided to implement multithreading. Here is the code:
import os, threading
def loop():
for x in range(800):
inizialize().start()
class inizialize(threading.Thread):
def run(self):
self.program()
def program(self):
n = list(range(778))
n.pop(0)
for z in n:
Path = ("/home/user/Desktop/files/recup_dir.%s/" % (z))
filelist = os.listdir(Path)
print (Path)
for x in filelist:
try:
with open(Path + x, "r", encoding="ascii") as y:
for line in y:
if "firefox" in line:
print ("Found in %s !" % (x))
exit (1)
except:
pass
loop()
The problem is that threads (that are 800) always do the same operations and they never pass to the next folder. They always stay on the first one (recup_dir.1).
How can I do to let threads continue searching in the other folders?