Challenge:
change the code so that only .py and .txt files of a given directory are listed.
''' filename_list_given_dir1.py
use module glob to list all the filenames of .jpg files
or any extension(s) you specify in a given directory
'''
import glob
import os
# all files (split off file names) in a given directory
directory = "C:/Temp/*.jpg"
# this would give you all files
#directory = "C:/Temp/*.*"
for path in glob.glob(directory):
#print(path) # test
# separate path from filename
dirname, filename = os.path.split(path)
print(filename)