Some_dude
Some_dude

Reputation: 139

Is there a way to reference a username in a path when you dont know what username is on the system?

I'm doing a school project that requires me to write a virus, I wanted to make a virus that deletes files on a system, but when using

os.remove()

it requires me to already have a path, does anyone know how to get around this?

I've already tried

path = (r"C:\Users\%username%\Desktop")

but that doesn't help and just leads to a Windows can't find path specified problem

Upvotes: 0

Views: 500

Answers (1)

Chris
Chris

Reputation: 29742

Use getpass:

import getpass
curuser = getpass.getuser()
# Current User name
path = "C:\Users\%s\..." % curuser

Upvotes: 1

Related Questions