1import os
2directory = 'the/directory/you/want/to/use'
3
4for filename in os.listdir(directory):
5 if filename.endswith(".txt"):
6 #do smth
7 continue
8 else:
9 continue
1import os
2
3for filename in os.listdir(directory):
4 if filename.endswith(".asm") or filename.endswith(".py"):
5 # print(os.path.join(directory, filename))
6 continue
7 else:
8 continue
1import os
2
3for filename in os.listdir(directory):
4 if filename.endswith(".asm") or filename.endswith(".py"):
5 # print(os.path.join(directory, filename))
6 continue
7 else:
8 continue
9
1# python 3
2import os
3
4for dirpath, dirnames, filenames in os.walk(dir_path):
5 print(dirpath)
6 print(dirnames)
7 print(filenames)
8
9# python 2
10import os.path
11
12def print_it(x, dir_name, files):
13 print(dir_name)
14 print(files)
15
16os.path.walk(your_dir, print_it, 0)
1basepath = "pathtodir/DataFiles/"
2for filename in os.listdir(basepath):
3 if filename.endswith(".log"):
4 print(os.path.join("./DataFiles", filename))
5
6 with open(basepath + filename) as openfile:
7 for line in openfile:
8 ........
1import glob
2
3globIterator = glob.iglob(path, recursive=True)
4
5run = True
6while(run == True):
7 try:
8 print(next(globIterator))
9 except:
10 run = False
11