Search code examples
pythonfilepathfilenameslistdir

How to only get files without extensions?


My problem is to get ONLY files without extensions. I mean - I have a dictionary and there are some files without extensions and some files with extensions (.xml, .csv, etc)

I want that my code would only read files without extensions.

Now, it's reading every file in the dictionary "Dir".

path = 'C:/Users/STJ2TW/Desktop/Dir/'
for filename in os.listdir(path):
    fullname = os.path.join(path, filename)

Thanks in advance!


Solution

  • If there are no dots in your files, you can do :

    path = 'C:/Users/STJ2TW/Desktop/Dir/'
    for filename in os.listdir(path):
        if '.' not in filename:
            fullname = os.path.join(path, filename)