Open Pin-Jiun opened 1 year ago
讀取多個檔案也可以使用
import tkinter as tk
from tkinter import filedialog
import os
def get_the_folder_path():
root = tk.Tk()
root.withdraw()
folder_path = filedialog.askdirectory()
print(folder_path)
return folder_path
#read mutiple files from a Folder to a list
def get_mutiple_files_name_list():
folder_path = get_the_folder_path()
files_list= os.listdir(folder_path) #get the all file list
return files_list
glob.glob(pathname, *, recursive=False)
會返回一個list, list裡面會包含你搜尋到符合你資格的file, dirCreate directory
os.mkdir(os.path.join("Folder_1") os.mkdir(os.path.join("Folder_1", "File_1.txt")) os.mkdir(os.path.join("Folder_1", "File_2.csv")) os.mkdir(os.path.join("Folder_1", "File_3.txt"))
備註:這邊其實都是建立資料夾,只是為了示範用,所以加上檔名,實際上並非檔案
https://ithelp.ithome.com.tw/articles/10262521