Hi,i want to access the filename of a any file using python.Ex.
Suppose a folder contain some files Picture1.jpg,picture2.jpg,mypic.jpg..etx i want to make a program which will print all the file name
Picture1.jpg
picture2.jpg
mypic.jpg


of the certain folder.And the folder can have random file name but with .JPG extension.

I wanna chk if the file is .jpg extension????

Recommended Answers

All 2 Replies

So, for each file, examine this: os.path.splitext(the_file_name)[-1].lower()

This list .jpg .JPG, .jpeg etc file in current folder:

import os
exts = '.jpg', '.jpeg'
files = os.listdir(os.curdir)
print([filename for filename in files if filename.lower().endswith(exts)])
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.