Code: Select all
import sys
## ESP32
_root = sys.path[1].split('lib')[0] #['', '/flash/lib']
print(_root) # /flash/
## ESP8266
_root = sys.path[1].split('lib')[0] #['', '/lib', '/']
print(_root) # /
Code: Select all
import sys
## ESP32
_root = sys.path[1].split('lib')[0] #['', '/flash/lib']
print(_root) # /flash/
## ESP8266
_root = sys.path[1].split('lib')[0] #['', '/lib', '/']
print(_root) # /
Code: Select all
MicroPython v1.8.1-1435-g528aeb3-dirty on 2017-03-14; ESP module with ESP8266
Type "help()" for more information.
>>> import os
>>> os.listdir('/')
['flash']
>>>
Code: Select all
del sys.path[:]
sys.path.extend(['','/flash/lib'])
Code: Select all
// Entries for sys.path
Q(/)
Q(/lib)
Code: Select all
MicroPython v1.8.1-1435-g528aeb3-dirty on 2017-03-14; ESP module with ESP8266
Type "help()" for more information.
>>> import os, sys
>>> sys.path
['', '/flash/lib', '/flash']
>>> os.listdir('/')
['flash']
>>> os.listdir('/flash')
['boot.py', 'main.py', 'roundrobin.py', 'utelnetserver.py', 'art.py', 'art1.py', 'aremote.py']
>>>