I would like python to find the current user's username and then implement it into the following line of code.
I have used multiple suggestions given on here but they don't seem to work, the only thing that works is when I manually enter the username in below line of code starting with root = filedialog…
then the folder opens up in the C:\Users\username\Documents
as it should.
from tkinter import *
from tkinter import filedialog
import getpass
import os
gui = Tk()
gui.geometry('200x400')
#user input
root = filedialog.askdirectory(initialdir="C:\\Users\\username\\Documents", title="Select your root
folder")
def printName(event):
print("Config folder created")
#Create a folder structure
project = "1"
app = "bl"
mw = "jb"
a = "modules"
b = "com"
c = "mac"
d = "f"
e = "config"
f = "main"
path = f"{root}/{project}/{app}/{mw}/{a}/{b}/{c}/{d}/{e}/{f}".lower().replace(" ","")
print(path)
#If path exists don't create if not create path
if not os.path.exists(path):
os.makedirs(path)
print("Config folder created")
button_1 = Button(gui, text="Config folder")
button_1.bind("<Button-1>", printName)
button_1.pack()
gui.mainloop()