Search code examples
pythonpython-3.ximagejpegglob

Hidden dot underscore ._ before name of image files in a directory while reading them using glob


I am trying to read images from a directory. The directory has images named like-

person1_bacteria_1.jpeg
person1_bacteria_2.jpeg
person2_bacteria_3.jpeg

I am trying to grab these images using glob function.

images = images_directory.glob('*.jpeg')

The problem is, while I print the directory of the files I have just read, I found that some of the files have dot underscore (._) before them.

For example-

dir/._person1_bacteria_2.jpeg

I checked the image files in the directory again and again but there was no image name with ._ before it.

How do I avoid reading files whose name have dot underscore (._) before it?

I am running this in an windows machine.


Solution

  • I think this files are just thumbnail files. if you look with os.path.getsize(filename) you can probably confirm this hypothesis.

    The reason you don't see this files is that they are probably marked as hidden files. Try to configure your windows explorer such, that it shows all files. ( https://support.microsoft.com/en-us/help/14201/windows-show-hidden-files )