0

Here i am trying to copy a file from a source location to the target location.

from shutil import copy2
sourcefile = "file.avro"
targetdirectory = "/home"
copy2(soucefil,targetdirectory)

But i need to copy the file to the new location with a different name say file.avro.copy Is there any python library that can be used for renaming file while copying itself. Donot want to copy and rename in two different steps.

SaAk
  • 75
  • 2
  • 13

1 Answers1

1

Use shtutil function 'copyfile(old_path, new_path)':

from shutil import copyfile

copyfile('myfile.txt', '/home/myfileCopy.txt')
Ali Sajjad
  • 3,589
  • 1
  • 28
  • 38