Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import threading
- import queue
- import os
- class SearchFiles(threading.Thread):
- def __init__(self, q):
- self.lock = threading.Lock()
- self.files = []
- def run(self):
- path = q.get()
- if os.path.exists(path):
- print("Searching...")
- for root, dirs, files in os.walk(path):
- for f in files:
- q.put(os.path.join(root, f))
- self.lock.acquire()
- self.append()
- self.lock.release()
- else:
- files = self.result()
- tam = len(files)
- for f in files:
- print(f)
- print("%d files" % tam)
- def append(self):
- self.files.append(q.get())
- def result(self):
- return self.files
- if __name__ == '__main__':
- q = queue.Queue()
- q.put("C:\\Windows")
- files = SearchFiles(q)
- files.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement