List all the files having ext .txt in the current directory .
L = [txt for f in os.walk('.')
for txt in glob(os.path.join(file[0], '*.txt'))]
I want to avoid files from one specific directory and its subdirectories . Lets say I do not want to dig into folder3
and its available subdirectories to get the .txt
files. I tried below
d = list(filter(lambda x : x != 'folder3', next(os.walk('.'))[1]))
but further steps not able to figure it out.How to include both to work together?
EDIT:
I tried referring the link provided as already answered query but I am unable to get desired output with below and surprisingly getting empty list as output for a
a=[]
for root, dirs, files in os.walk('.'):
dirs[:] = list(filter(lambda x : x != 'folder3', dirs))
for txt in glob(os.path.join(file[0], '*.txt')):
a.append(txt)