1import os
2#full path
3dir_path = os.path.dirname(os.path.realpath(__file__))
4
5#current dir
6cwd = os.getcwd()
7
1from pathlib import Path
2for txt_path in Path("/path/folder/directory").glob("*.txt"):
3 print(txt_path)
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
1from os import listdir
2from os.path import isfile, join
3onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))]
4