Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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".

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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)
            
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading