Mohamed Belkamel
Mohamed Belkamel

Reputation: 429

Get path to certain folder in python

I need to get the location of the startup folder, like so: on my computer it looks like this:

C:\\Users\\pc\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup 

but how do I get the path to this folder on any computer using Python?

I'm trying to use the function shutil.copy2() replacing the A below with the path to startup

shutil.copy2("C:\\Users\\NAME_OF_USER\\Downloads\\file.exe", "A")

Upvotes: 0

Views: 241

Answers (1)

tfw
tfw

Reputation: 383

You can expand the USERPROFILE environment variable in Windows to get the path to the current user's directory

import os

a = os.path.normpath(os.path.expandvars('$USERPROFILE') + 'AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup')
shutil.copy2("C:\\Users\\NAME_OF_USER\\Downloads\\file.exe", a)

Upvotes: 1

Related Questions