Firstly, thanks Carl_M! I will try to ask this question with more simple code. Using tkinker-
the user is asked to select the directory and new subfolder. That works.
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:folderMy_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)
Advertisement
Answer
Try
def openFile(): filename = filedialog.askopenfilename(initialdir = r'L:folderMy_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)