0

I am using OS to walk through a very large number of files. Due to performance reasons I am only interested in the files which do not end in "_TT.docx"," TT.docx", "-TT.docx", " tt.docx", "_tt.docx" or ".pdf"

I only want the docx files without any of the TT combination or the pdfs.

I tried the code below to eliminate several parameters at the same time but it does not work (identation error). I don't find it. Where do I go wrong?

files_in_dir = []
others_in_dir = []
targets_in_dir = []
# r=>root, d=>directories, f=>files
for r, d, f in os.walk(location):
   for item in f:
          if '.pdf' in item:
             pdfs_in_dir.append(os.path.join(r, item))
                elif 'SS' in item:
                    others_in_dir.append(os.path.join(r, item))
                elif '.docx' in item:
                    targets_in_dir.append(os.path.join(r, item))
  • `if 'TT.docx' or '.pdf' not in item` doesn't do what you think it does (hint: https://stackoverflow.com/questions/20002503/why-does-a-b-or-c-or-d-always-evaluate-to-true) – Pranav Hosangadi Mar 10 '21 at 05:03
  • it pulls the complete file list with everything in it. I checked with {len} – Nimrod Ets Mar 10 '21 at 08:01
  • @PranavHosangadi: I tried the solution in the post but it jumps to the first true; now I tried updated code above – Nimrod Ets Mar 10 '21 at 09:09

0 Answers0