-1

Inside of 'Folder X' I would like to create a copy Invoice.xlsx which is already inside of Folder X and create a copy of it with a new name also inside of Folder X.

How is this done with Python?

Alex
  • 486
  • 1
  • 7
  • 19
  • 2
    Possible duplicate of [How do I copy a file in python?](http://stackoverflow.com/questions/123198/how-do-i-copy-a-file-in-python) – Arya McCarthy Apr 29 '17 at 18:26

3 Answers3

1

Please use the Stack Overflow search feature. This question has been answered already.

See How do I copy a file in python? for example.

from shutil import copyfile
copyfile("/path/to/folder X/Invoice.xslx", "/path/to/folder X/Invoice-Copy.xslx")
thiagowfx
  • 4,832
  • 6
  • 37
  • 51
0

One approach would be with subprocess, which lets you run shell commands:

import subprocess
subprocess.run(['cp', 'Invoice.xlsx', 'Invoice_2.xlsx'])
Arya McCarthy
  • 8,554
  • 4
  • 34
  • 56
0
# read file
with open('Folder X/Invoice.xlsx', 'rb') as f:
    file = f.read()

# write file
with open('Folder X/Invoice_Copy.xlsx', 'wb') as f:
    f.write(file)
heyu91
  • 1,174
  • 11
  • 18