I have one xlsx file and I want to create with python script another xlsx file equal to the first one. How can I do? Have you an example script?
Asked
Active
Viewed 66 times
1 Answers
1
shutil can hep you do this.
from shutil import copyfile
copyfile(src, dst)
Taken from this answer although it answers the general case. How do I copy a file in python?
-
It seems interesting... and if I want to copy a file and save him in the same directory of the first one but with a different name... how may I do that? – Michele Della Mea Apr 04 '16 at 14:08
-
You have to just specify the full path of both file you want to copy and location you want to copy to. So copyfile("/Users/bob/file.xlsx","/Users/bob/copy_of_file.xlsx",) – bamdan Apr 04 '16 at 14:12
-
yeah sure but i want to do it in a dynamical way... for that I was searching a similar function. – Michele Della Mea Apr 04 '16 at 14:15
-
Sure, yes that's possible. If by dynamic you mean that the file name is dynamic? Would ned a bit more detail to help. – bamdan Apr 04 '16 at 14:31
-
I mean that I want to create a python script in which I write only a path (for example "C:\Users\lucas\Desktop\bom\merged.xlsx" and the result must be another .xlsx equal to the first one and located in the same folder ("bom" in this case) but with a different name (for example adding a 2 after the name of the first file so "merged2.xlsx" in this case). So both name file and path must be dynamic. – Michele Della Mea Apr 04 '16 at 14:52