0

I am trying to scan all files on Linux system using os.walk, however i want to exclude some non relevant directories. Below you can see my test code where i am trying to implement this, however it does not work correctly. My question is how do i add filenames/directories to exclude from results.

import os

exc=["/tmp","/meh"]

def get_filepaths(directory):
    file_paths = []
    for root, directories, files in os.walk(directory):
        for filename in files:
                filepath = os.path.join(root, filename)

                for x in exc:
                 print(x)
                 if x in filepath:
                  pass
                else:
                 file_paths.append(filepath) 
    return file_paths

full_file_paths = get_filepaths("/")
martineau
  • 119,623
  • 25
  • 170
  • 301
pauts
  • 119
  • 1
  • 8

0 Answers0