7

I am trying to copy an excel file and rename it. For example I have a file HI.xlsx and I want to copy it and rename it as BYE.xlsx.
My code to do this is below and when I run it, the file BYE.xlsx is created, but it is corrupted.

Here is what I am using:

fIn = open(r"HI.xlsx")
fOut = open(r"BYE.xlsx", "w")
ManishChristian
  • 3,694
  • 3
  • 21
  • 47
Horv
  • 73
  • 1
  • 1
  • 4

1 Answers1

12

You should be using shutil.copy():

shutil.copy("HI.xlsx", "BYE.xlsx")
Padraic Cunningham
  • 168,988
  • 22
  • 228
  • 312
DeepSpace
  • 72,713
  • 11
  • 96
  • 140