Append file in sd card ec200u

Can we append a txt file stored in SD card using quecpython.

Hi Ravi Shankar,

Yes, you can append to a .txt file on an SD card using QuecPython, but you don’t use the ql_fs API for that. Instead, use standard Python file I/O after mounting the SD card.

Steps:

Mount the SD card

import uos
sd = uos.VfsSd(“sd_fs”)
uos.mount(sd, “/sd”)

Open the file in append mode

file_path = “/sd/mylog.txt”
with open(file_path, “a”) as f: # ‘a’ for append mode
f.write(“New line of text\n”)

“a” mode places the file pointer at the end of the file.

If the file does not exist, it will be created automatically.

Close the file
Using with open(…) automatically handles closing.

Notes:

ql_fs API is mainly for file system operations like checking existence, creating JSON files, or copying files. It does not provide a direct append function.

Using standard Python I/O is the recommended way to append text.

Please refer to the detailed guide from the link provided below:

ql_fs - Advanced Operations of Files - QuecPython

Have a great day!

Best Regards,
Ananthan

1 Like