PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, November 2, 2022

[FIXED] How to only get files without extensions?

 November 02, 2022     file, filenames, listdir, path, python     No comments   

Issue

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)
            


Answered By - Said Amz
Answer Checked By - Mary Flores (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing