import os # 読み込むフォルダのパスを指定 folder_path = '/Users/xxxxx/Documents/' # フォルダ内の.txtファイルを取得 files = [f for f in os.listdir(folder_path) if f.endswith('.txt')] # ファイルを順番に読み込む for file in sorted(files): file_path = os.path.join(folder_path, file) with open(file_path, 'r', encoding='utf-8') as file: content = file.read() print(f'Contents of {file}:') print(content) print('---')