adafruit / Adafruit_CircuitPython_SD

SD card drivers for Adafruit CircuitPython
MIT License
37 stars 17 forks source link

os.listdir('/sd') returns empty from code.py, but correct in REPL. #16

Closed dt1900 closed 5 years ago

dt1900 commented 5 years ago

I'm following the post here: https://andyfelong.com/2019/03/pyportal-access-the-micro-sd-card/

What's odd is that os.listdir('/sd') returns empty results when running in code.py, but is correct in the REPL:

Auto-reload is on. Simply save files over USB to run them or enter REPL to disable. code.py output:

Press any key to enter the REPL. Use CTRL-D to reload. Adafruit CircuitPython 4.0.0-rc.1 on 2019-04-23; Adafruit PyPortal with samd51j20

import board import storage import adafruit_sdcard import os import digitalio import busio spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO) cs = digitalio.DigitalInOut(board.SD_CS) sdcard = adafruit_sdcard.SDCard(spi, cs) vfs = storage.VfsFat(sdcard) storage.mount(vfs, "/sd") os.listdir('/sd') ['.Spotlight-V100', '.fseventsd', 'test.txt', '._test.txt', 'TESTdir', 'hello', 'TESTfile.txt']

dt1900 commented 5 years ago

wrapping the list command as such:

print(os.listdir('/sd'))

gave me the expected results.