gpt4 book ai didi

python - 在 Tkinter 中使用 askdirectory() 选择文件夹时显示所有文件

转载 作者:行者123 更新时间:2023-12-05 06:58:09 26 4
gpt4 key购买 nike

在 Tkinter 中,我只需选择我的文件所在的文件夹。我正在使用 filedialog.askdirectory() 进行此操作。是否也可以在 UI 中查看文件夹中的文件?

最佳答案

通过提供文件扩展名来使用此功能(任何扩展名都可以)!
file_extension="niff"

def displayall ( file_extension):   

root = Tk()
root.withdraw()

path = filedialog.askdirectory()

# get data file names, all the file extention
os.chdir(path)

all_fNames0 = glob.glob(path + '/**/*.{}'.format(file_extension), recursive=True)
print("Total number of files:", len(all_fNames0))
print("All file names:", all_fNames0)

希望这对您有所帮助!

关于python - 在 Tkinter 中使用 askdirectory() 选择文件夹时显示所有文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64710157/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com