1import glob, os
2os.chdir("/mydir")
3for file in glob.glob("*.txt"):
4 print(file)
1from pathlib import Path
2for txt_path in Path("/path/folder/directory").glob("*.txt"):
3 print(txt_path)
1import os
2
3def find_files(filename, search_path):
4 result = []
5
6# Wlaking top-down from the root
7 for root, dir, files in os.walk(search_path):
8 if filename in files:
9 result.append(os.path.join(root, filename))
10 return result
11
12print(find_files("smpl.htm","D:"))
1# option A (i think this is faster, not in micropython)
2
3import os
4
5if os.path.isfile("test.dat"):
6 print("yes") #file found
7else:
8 print("no") #file not found
9
10# also this is posible
11# from os.path import isfile
12# if isfile("test.dat"):
13
14
15# option B (posible in micropython)
16
17import os
18
19if "test.dat" in os.listdir():
20 print("yes") # file found
21else:
22 print("no") # file not found
23
24# os.lisdir() return a array whit all the files found in the directory