Python copy files to a new directory and rename if file name already exists

后端 未结 4 630
梦毁少年i
梦毁少年i 2021-02-02 06:24

I\'ve already read this thread but when I implement it into my code it only works for a few iterations.

I\'m using python to iterate through a directory (lets call it m

4条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-02 07:20

    For me shutil.copy is the best:

    import shutil
    
    #make a copy of the invoice to work with
    src="invoice.pdf"
    dst="copied_invoice.pdf"
    shutil.copy(src,dst)
    

    You can change the path of the files as you want.

提交回复
热议问题