9

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,759
  • 3
  • 22
  • 50
Horv
  • 93
  • 1
  • 1
  • 4

1 Answers1

13

You should be using shutil.copy():

shutil.copy("HI.xlsx", "BYE.xlsx")
Padraic Cunningham
  • 176,452
  • 29
  • 245
  • 321
DeepSpace
  • 78,697
  • 11
  • 109
  • 154