1

I am trying to get the list of .ini files from a given directory. it works fine except it is missing the hidden directory.

Below is the piece of code I am using, I need to include the hidden directory also when I am doing this.

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

    for name in files:

        if name.endswith(".ini"):    

            file_list.append(os.path.join (root,name))
roganjosh
  • 12,594
  • 4
  • 29
  • 46
Krishna
  • 21
  • 4
  • 1
    are you sure? http://stackoverflow.com/questions/13454164/os-walk-without-hidden-folders. Seems that all directories are scanned. – Jean-François Fabre Feb 27 '17 at 17:12
  • 5
    What OS are you on? – roganjosh Feb 27 '17 at 17:14
  • 1
    [`os.walk`](https://docs.python.org/3/library/os.html?highlight=os.walk#os.walk) is documented to skip `.` and `..` and *symbolic links.* It shouldn't skip any other dirs. Can you provide some real code and a set of example problems that you're having? – aghast Feb 27 '17 at 17:23
  • thank you, the hidden dir what is missing is start with .registry, and it is configured as symbolic link, I think that is why it is skipped. Can you help what is the other function I can use to include them ? – Krishna Feb 27 '17 at 18:20
  • Try `os.listdir` and possibly try glob. – Carl_M Mar 03 '22 at 22:59

1 Answers1

0

In macos, I had the same issue. I have no idea why some directories are being ignored arbitrarily in dirs.

As suggested in @Carl_M 's comment, I was able to get the full list of directories by using os.listdir:

import os

for root, dirs, files in os.walk(path):
    full_list_of_dirs = os.listdir(path)
Pablo Guerrero
  • 936
  • 1
  • 12
  • 22