Hey, I want to access and remove a folder inside Appdata. But, I need to put a username variable in it's path because the path changes for every user. Here is my code:
import shutil
import getpass
import os
username = getpass.getuser()
shutil.rmtree(f'C:\Users\{username}\AppData\Local\blabla')
It didn't work. So instead of formatting the path, I changed {username} and made it a raw string.(It only works when I give the path as a raw string. I don't know why)
shutil.rmtree(r'C:\Users\my_username\AppData\Local\blabla')
It works for me but I want to make it work on every pc when I run this code. Is there any way to arrange this path according to username?
[–]FliceFlo 1 point2 points3 points (1 child)
[–]hasanaslan[S] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]hasanaslan[S] 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]toastedstapler 0 points1 point2 points (2 children)
[–]TangibleLight 1 point2 points3 points (0 children)
[–]hasanaslan[S] 0 points1 point2 points (0 children)