SD-Card


import os

//Read file
with open('/sd/FileName.*','r') as fs:
  print(fs.read())

//Write file
with open('/sd/test.txt','w+') as fs:
  fs.write('Hello World')

//File read and write mode
w is opened for writing,
w+ open in read-write mode
r open in read mode
r+ open in read-write mode
a Open in append mode

//Set the file cursor
fs.seek(0)

//View catalog
os.listdir('/sd/DirectoryPath')

//Determine whether the path is a file
os.stat('/sd/FilePath')[0] == 0x8000)

//Determine whether the path is a directory
os.stat('/sd/DirectoryPath')[0] == 0x4000)

//Determine whether the file exists in the specified directory
'FileName.*' in os.listdir('/sd/DirectoryPath')
On This Page