UIFlow Guide
该程序使用SD卡进行文件和文件夹的创建、删除、重命名和读写操作。主要步骤如下:
m5test.txt
文件和m5 folder
文件夹(如果存在)。m5.txt
,内容为“welcome to M5”,然后读取并打印文件内容。m5test.txt
文件是否存在,并打印检查结果。m5.txt
文件为m5test.txt
,并再次检查其是否存在。m5 folder
中创建m5test.txt
文件并追加写入“hello to M5”,然后读取并打印全部内容。from 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')
passtf.delete_file('')
tf.rename_file('','')
tf.delete_folder('')