0

So, I'm looping through my files and folders as follows:

for root, dirs, files in os.walk(img):

How can we avoid including the current (.) and parent (..) directories in such search?

Thanks.

Simplicity
  • 47,404
  • 98
  • 256
  • 385
  • not sure your question is clear enough, the actual entries `.` and `..` do not show up in the os.walk results. – Pykler Jan 16 '18 at 17:26

1 Answers1

0

os.walk() wouldn't plow through your parent directory (I'm assuming you mean the parent of img), so you wouldn't need to worry there. If you just want to skip the current directory assigned to img, it's simple:

for root, dirs, files in os.walk(img):
    if root == img: continue
    # your code for the children dirs and files here #
r.ook
  • 13,466
  • 2
  • 22
  • 39