I am trying to isolate file names from paths imported using "filedialog.askopenfilenames". I am doing that so I can use them later in plots.
Let us say for example that I imported three excel files that have the following names: "sample_excel_1","sample_excel_2.xlsx","sample_excel_3.xlsx"
The output in my case is the full paths of the files( i.e., ('//tudelft.net/staff-homes/K/mkhadijeh/Desktop/Python/sample_excel_1.xlsx', '//tudelft.net/staff-homes/K/mkhadijeh/Desktop/Python/sample_excel_2.xlsx', '//tudelft.net/staff-homes/K/mkhadijeh/Desktop/Python/sample_excel_3.xlsx') )
I would like the outputs to be instead ("sample_excel_1","sample_excel_2.xlsx","sample_excel_3.xlsx")
Any help!
The code is below:
import tkinter
from tkinter import *
from tkinter import filedialog
import numpy as np
filename = filedialog.askopenfilenames(initialdir="c:/", title="Selecte a file", filetypes=(("Excel files", "*.xlsx"),("All files","*.*")))
a = filename
print(a)
I want a to be a list so I can easily access it later (i.e., ["sample_excel_1","sample_excel_2.xlsx","sample_excel_3.xlsx"] )