Copy Files to Flash
-
I haven't found anything after hours of searching!
How to copy files from SD card to Flash.
Or move them directly from the SD card to the flash memory when booting so that the files on the SD card are deleted afterwards?
-
@robert-hh Top
-
@wolli01 uos.remove()
-
@robert-hh Thank you very much, sir.
Is there a command to delete the unnecessary files on the SD card?
-
@wolli01 Update again using a larger buffer and making it work for all kind of files.
-
@wolli01 I updated it a few seconds ago after testing
-
@robert-hh Thanks, I'll see how I use it.
-
@wolli01 So it is different form what you wrote below. You want to copy the file if it exists. And no, there is not copy file command. It does not exist in uos or os. You have to write your own code for it, like:
def copy(s, t): with open(s, "rb") as s: with open(t, "wb") as t: while True: b = s.read(4096) if not b: break t.write(b)
-
@robert-hh das verstehe ich nicht so ganz.
Hier mal wie ich es gerne haben möchte doch leider gibt es wohl kein kopierbefehl?try: f = open('/sd/wlan.txt', "r") exists = True print('Datei vorhanden') f.close() copy('/sd/wlan.txt', '/flash/wlan.txt') except Exception: exists = False print('Datei nicht vorhanden')```
-
@wolli01 You could try to 'stat' the file. If that fails, the file does not exist. e.g.:
try: from uos import stat f = stat("/flash/file_to_probe") # file exists except OSError: # file does not exist.
-
@robert-hh i just want to check if there is a certain file in the flash directory when bidding and if not the file should be copied from my SD card to the flash directory.
-
@wolli01 Depends on what you are using. Using an ftp client like filezilla is just drag & drop. At the REPL prompt there is no basic feature. You have to code a copy file function is python.