How to recursively remove files with mpremote? #9802
|
I recently use mpremote instead of rshell and I like it, but I cannot find a good way to remove files from the device recursively (without supplying all the file paths manually). Has anyone any advice on how to do this with mpremote? There is a rm and a rmdir command but suppling -r argument is not supported and using |
Replies: 9 comments 15 replies
|
you can look at here: #!/usr/bin/python
# -*-coding:utf-8 -*-
"""
-------------- Description: ------------------
FileName : main.py
Author : isaac
ProjectName : recursively remove files with boards.
IDE Version : PyCharm
Date:2020/11/1 14:20
QQ:287000822 E-mail: gomehome@qq.com
------------------- END ----------------------
"""
__author__ = 'Isaac'
import os
m_list = []
m_list.append(os.listdir())
for i in m_list[0]:
os.remove(str(i))
print('remove all done!') |
|
This is a frequently requested feature for mpremote! It's on the todo list (PRs welcome!). |
|
You could consider using mpr. It merely wraps Of course this "trick" uses mpr's directory/path inference and exploits the wildcard file list generated by your shell to pass those local file names to the remote device. It assumes those same names exist in the analogous directory there. |
|
Ha! That's a tricky question... I've been working on a simple on-board solution... (save as 'kill_ffs.py' on the root path of the device) It still has some issues with getting all the directories removed but you might be able to fix that... btw... it has code to skip the script itself and 'boot.py'. I think it would still work even if you still delete them. Hope this helps! |
|
Take a look at https://github.com/Josverl/mpremote_config/blob/master/snippets/wipe_folder.py And the config.py a level above that As a way to simply add just about anything you can think of, as a command to mpremote. |
|
The rm() command of upysh.py in micropython-lib removes directories as well, if told so. |
|
(pip install mpr / https://github.com/bulletmark/mpr ) |
|
Recursive remove is now supported by Use with caution! |

This is a frequently requested feature for mpremote! It's on the todo list (PRs welcome!).