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? -
@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.
-
@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 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 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 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 Thanks, I'll see how I use it.
-
@wolli01 I updated it a few seconds ago after testing
-
@wolli01 Update again using a larger buffer and making it work for all kind of files.
-
@robert-hh Thank you very much, sir.
Is there a command to delete the unnecessary files on the SD card? -
@wolli01 uos.remove()
-
@robert-hh Top
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better đź’—
Register Login