How to copy a file from a network share to local disk with variables?

前端 未结 4 959
走了就别回头了
走了就别回头了 2021-02-02 18:21

If I use the following line:

shutil.copyfile(r\"\\\\mynetworkshare\\myfile.txt\",\"C:\\TEMP\\myfile.txt\")

everything works fine. However, what

4条回答
  •  庸人自扰
    2021-02-02 18:27

    The r is for "raw string", not for relative. When you don't prefix your string with r, Python will treat the backslash "\" as an escape character.

    So when your string contains backslashes, you either have to put an r before it, or put two backslashes for each single one you want to appear.

    >>> r"\\myfile" == "\\\\myfile"
    True
    

提交回复
热议问题