How to get Desktop location?

后端 未结 7 658
情深已故
情深已故 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 16:08

    On Unix or Linux:

    import os
    desktop = os.path.join(os.path.join(os.path.expanduser('~')), 'Desktop') 
    

    on Windows:

    import os
    desktop = os.path.join(os.path.join(os.environ['USERPROFILE']), 'Desktop') 
    

    and to add in your command:

    shutil.copy(txtName, desktop)
    

提交回复
热议问题