Untitled
unknown
plain_text
a year ago
1.3 kB
23
Indexable
import os
def read_files_in_folder(folder_path, substring):
"""
Đọc nội dung của tất cả các file .txt trong thư mục được chỉ định.
"""
# Lấy danh sách các file trong thư mục
files = [f for f in os.listdir(folder_path) if f.endswith('.txt')]
for filename in files:
file_path = os.path.join(folder_path, filename)
try:
with open(file_path, 'r', encoding='utf-8') as file:
print(f"Reading file: {filename}")
# Đọc nội dung của file
content = file.readlines() # Đọc từng dòng và lưu vào danh sách
temp = []
# Xử lý nội dung nếu cần
# Sau khi content được xử lý sẽ lưu vào temp
temp = []
except FileNotFoundError:
print(f"File '{file_path}' not found.")
except IOError as e:
print(f"Error reading file '{file_path}': {e}")
# Đường dẫn đến thư mục chứa các file .txt
folder_path = 'D:\.venv\inputcsv' # Thay thế bằng đường dẫn đến thư mục chứa các file .txt
# Gọi hàm để đọc nội dung các file
read_files_in_folder(folder_path, substring)
Editor is loading...
Leave a Comment