← index #4775Issue #8807
Duplicate · high · value 3.513
QUERY · ISSUE

Micropython file truncate doesn't exist

openby morrison93opened 2019-05-10updated 2025-10-03
enhancement

Is there any alternative in MicroPython to truncate a file at the current seek position? I don't want to just empty the file, I want to truncate it at a position.

The truncate function doesn't exist ( https://docs.micropython.org/en/latest/esp8266/tutorial/filesystem.html?highlight=open#creating-and-reading-files https://docs.micropython.org/en/latest/library/builtins.html?highlight=open#open )

Any alternatives?

I thought about copying the whole contents to a new file, but I wanted to avoid that since I'm limited to memory and storage(working on a LoPy4)

CANDIDATE · ISSUE

Add `truncate()` to `io.FileIO`

openby AmirHmZzopened 2022-06-23updated 2022-06-23
enhancement

There's lack of truncate() ability in FileIO or in os module. I should also mention truncate() method exists in in io.IOBase and os modules of cpython. Is there any special cost or complexity in filesystem level for implementing this in Micropython ?

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied