How to get Desktop location?

后端 未结 7 686
情深已故
情深已故 2020-12-08 15:30

I\'m using Python on Windows and I want a part of my script to copy a file from a certain directory (I know its path) to the Desktop.

I used this:

sh         


        
7条回答
  •  南笙
    南笙 (楼主)
    2020-12-08 15:54

    You can use os.environ["HOMEPATH"] to get the path. Right now it's literally trying to find %HOMEPATH%/Desktop without substituting the actual path.

    Maybe something like:

    shutil.copy(txtName, os.path.join(os.environ["HOMEPATH"], "Desktop"))
    

提交回复
热议问题