Copy files

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
twist
Posts: 7
Joined: Thu Jan 21, 2021 12:36 pm

Copy files

Post by twist » Thu Jan 21, 2021 7:29 pm

hi ,
i dont find a command os.xxx for copy a file.
any solution exist for this ?
ex same command like : cp file1 file2

thx !!!

twist
Posts: 7
Joined: Thu Jan 21, 2021 12:36 pm

Re: Copy files

Post by twist » Thu Jan 21, 2021 9:24 pm

OK great i found the lib shutil .. awesome for mae a copy file

davef
Posts: 811
Joined: Thu Apr 30, 2020 1:03 am
Location: Christchurch, NZ

Re: Copy files

Post by davef » Fri Apr 30, 2021 9:14 am

Got it to work by first opening both files:

Code: Select all

fileA = open('/ramdisk/datalog.csv', 'rb')
fileB = open('/datalog.csv', 'wb')
copyfileobj(fileA, fileB)
Last edited by davef on Fri Apr 30, 2021 10:12 am, edited 1 time in total.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Copy files

Post by pythoncoder » Fri Apr 30, 2021 10:08 am

It works fine here on an rp2.
Peter Hinch
Index to my micropython libraries.

davef
Posts: 811
Joined: Thu Apr 30, 2020 1:03 am
Location: Christchurch, NZ

Re: Copy files

Post by davef » Fri Apr 30, 2021 10:14 am

Just beat me to it. When I first tried it I didn't use fileA/fileB but the filenames :(

Post Reply