Home > Software design >  how to copy files in python without os.rename and shutil library?
how to copy files in python without os.rename and shutil library?

Time:10-03

I have a question about how to copy files without using shutil and os.rename.I have some photos and some videos that I have to copy them in another folder.I can't use shutil and os.rename because this is a condition for that python exercise.I tried open for copy file but only work for text and didn't work for photos and videos

CodePudding user response:

open file in binary mode, and write in binary mode

original_file = open('C:\original.png', 'rb') # rb = Read Binary
copied_file = open('C:\original-copy.png', 'wb') #wb = Write Binary

copied_file.write(original_file.read())

original_file.close()
copied_file.close()

Python File Documentation

  • Related