Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    Copy Files to Flash

    Scheduled Pinned Locked Moved LoPy
    wipy 3.0lopy4fipycopyfile
    12 Posts 2 Posters 1.3k Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • W Offline
      Wolli01
      last edited by

      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-hhR 1 Reply Last reply Reply Quote 0
      • robert-hhR Offline
        robert-hh @Wolli01
        last edited by

        @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.

        W 1 Reply Last reply Reply Quote 0
        • W Offline
          Wolli01 @robert-hh
          last edited by

          @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.

          robert-hhR 1 Reply Last reply Reply Quote 0
          • robert-hhR Offline
            robert-hh @Wolli01
            last edited by

            @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.
            
            W 1 Reply Last reply Reply Quote 0
            • W Offline
              Wolli01 @robert-hh
              last edited by

              @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')```
              robert-hhR 1 Reply Last reply Reply Quote 0
              • robert-hhR Offline
                robert-hh @Wolli01
                last edited by robert-hh

                @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)
                
                W 1 Reply Last reply Reply Quote 1
                • W Offline
                  Wolli01 @robert-hh
                  last edited by

                  @robert-hh Thanks, I'll see how I use it.

                  robert-hhR 2 Replies Last reply Reply Quote 0
                  • robert-hhR Offline
                    robert-hh @Wolli01
                    last edited by

                    @wolli01 I updated it a few seconds ago after testing

                    1 Reply Last reply Reply Quote 0
                    • robert-hhR Offline
                      robert-hh @Wolli01
                      last edited by

                      @wolli01 Update again using a larger buffer and making it work for all kind of files.

                      W 1 Reply Last reply Reply Quote 0
                      • W Offline
                        Wolli01 @robert-hh
                        last edited by

                        @robert-hh Thank you very much, sir.
                        Is there a command to delete the unnecessary files on the SD card?

                        robert-hhR 1 Reply Last reply Reply Quote 0
                        • robert-hhR Offline
                          robert-hh @Wolli01
                          last edited by

                          @wolli01 uos.remove()

                          W 1 Reply Last reply Reply Quote 0
                          • W Offline
                            Wolli01 @robert-hh
                            last edited by

                            @robert-hh Top

                            1 Reply Last reply Reply Quote 0

                            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
                            • 1 / 1
                            • First post
                              Last post

                            Pycom on Twitter

                            Pycom