Home > Net >  File not landing in new directory created by askdirectory in tkinter
File not landing in new directory created by askdirectory in tkinter

Time:07-12

Firstly, thanks Carl_M! I will try to ask this question with more simple code. Using tkinker-

  1. the user is asked to select the directory and new subfolder. That works.

  2. Then browse for an exel file that will be modified as a df and sent to the new subfolder. That sort of works (thanks to Carl), but file doesn't go to the new subfolder. It goes to the selectPath. How can I add the path to the folder?

Used 'dirs = os.path.join(path.get(), folder.get())' to assign location, but it's not landing there.

def selectPath():   
    path_ = askdirectory()
    path.set(path_)
    
    
def create_subfolder():  
    print("folder_name: ", folder.get())
    print("path_name: ", path.get())
    dirs = os.path.join(path.get(), folder.get())

def openFile():
    filename = filedialog.askopenfilename(initialdir = r'L:\folder\My_file', filetypes=[("Excel Files", "*.xlsx")])
    os.startfile(filename)
    df = pd.read_excel(filename, sheet_name = 'Order Details')
    df.to_excel(((dirs)   'Intelliscan.xlsx'),index=False)

CodePudding user response:

Try

def openFile():
    filename = filedialog.askopenfilename(initialdir = r'L:\folder\My_file', filetypes=[("Excel Files", "*.xlsx")])
    os.startfile(filename)
    df = pd.read_excel(filename, sheet_name = 'Order Details')
    destination =  os.path.join(path.get(), folder.get(),'Intelliscan.xlsx')
    df.to_excel(destination,index=False)
  • Related