This program uses the SD card for file and folder creation, deletion, renaming, and reading/writing operations. The main steps are as follows:
m5test.txt file and m5 folder folder (if they exist).m5.txt with content “welcome to M5,” then read and print the file content.m5test.txt file exists and print the check result.m5.txt to m5test.txt and check its existence again.m5test.txt within m5 folder and append “hello to M5,” then read and print all content. Basefrom m5stack import *
from m5ui import *
from uiflow import *
from base.TF_Card import TFCARD
tf = TFCARD()
tf.init_sdcard(33, 19, 23, 20000000)
tf.delete_file('m5test.txt')
tf.delete_folder('m5 folder')
with open('/sd/m5.txt', 'w+') as fs:
fs.write('welcome to M5')
with open('/sd/m5.txt', 'r+') as fs:
print(fs.read())
print(tf.show_directory(''))
if tf.is_file_exist('m5test.txt'):
print('file is exist')
else:
print('file is not exist')
tf.rename_file('m5.txt','m5test.txt')
tf.create_folder('m5 folder')
print(tf.show_directory(''))
if tf.is_file_exist('m5test.txt'):
print('file is exist')
else:
print('file is not exist')
with open('/sd/m5test.txt', 'a') as fs:
fs.write('hello to M5')
with open('/sd/m5test.txt', 'r+') as fs:
print(fs.read()) tf.init_sdcard(33, 19, 23, 20000000) fs.tell() fs.read(0) fs.read() fs.readline() fs.seek(0) fs.write('') tf.is_folder_exist('') tf.is_file_exist('') tf.show_directory('') tf.create_folder('') with open('/sd/', 'a') tf.delete_file('') tf.rename_file('','') tf.delete_folder('')