fix_heading
import os
import re
folder = "." # Thư mục hiện tại, bạn có thể thay bằng đường dẫn cụ thể
for filename in os.listdir(folder):
# Chỉ xử lý file .txt
if filename.endswith(".txt"):
path = os.path.join(folder, filename)
# 1. ĐỔI NĂM TRONG NỘI DUNG FILE
with open(path, "r", encoding="utf-8") as f:
content = f.read()
# Tìm 2023, 2024, 2025 và thay bằng 2026
new_content = re.sub(r'202[3-5]', '2026', content)
with open(path, "w", encoding="utf-8") as f:
f.write(new_content)
# 2. ĐỔI NĂM TRONG TÊN FILE
new_filename = re.sub(r'202[3-5]', '2026', filename)
if new_filename != filename:
new_path = os.path.join(folder, new_filename)
os.rename(path, new_path)
print(f"Đã đổi tên: {filename} -> {new_filename}")
else:
print(f"Đã cập nhật nội dung: {filename}")
import os
folder = "." # Thư mục hiện tại
for filename in os.listdir(folder):
# Kiểm tra nếu từ "yobo" nằm trong tên file (không phân biệt chữ hoa chữ thường)
if "yobo" in filename.lower():
path = os.path.join(folder, filename)
try:
os.remove(path) # Lệnh xóa file
print(f"Đã xóa file: {filename}")
except Exception as e:
print(f"Không thể xóa {filename}: {e}")
print("--- HOÀN THÀNH XÓA FILE ---")
print("--- HOÀN THÀNH ---")
import re
folder = "." # Thư mục hiện tại, bạn có thể thay bằng đường dẫn cụ thể
for filename in os.listdir(folder):
# Chỉ xử lý file .txt
if filename.endswith(".txt"):
path = os.path.join(folder, filename)
# 1. ĐỔI NĂM TRONG NỘI DUNG FILE
with open(path, "r", encoding="utf-8") as f:
content = f.read()
# Tìm 2023, 2024, 2025 và thay bằng 2026
new_content = re.sub(r'202[3-5]', '2026', content)
with open(path, "w", encoding="utf-8") as f:
f.write(new_content)
# 2. ĐỔI NĂM TRONG TÊN FILE
new_filename = re.sub(r'202[3-5]', '2026', filename)
if new_filename != filename:
new_path = os.path.join(folder, new_filename)
os.rename(path, new_path)
print(f"Đã đổi tên: {filename} -> {new_filename}")
else:
print(f"Đã cập nhật nội dung: {filename}")
import os
folder = "." # Thư mục hiện tại
for filename in os.listdir(folder):
# Kiểm tra nếu từ "yobo" nằm trong tên file (không phân biệt chữ hoa chữ thường)
if "yobo" in filename.lower():
path = os.path.join(folder, filename)
try:
os.remove(path) # Lệnh xóa file
print(f"Đã xóa file: {filename}")
except Exception as e:
print(f"Không thể xóa {filename}: {e}")
print("--- HOÀN THÀNH XÓA FILE ---")
print("--- HOÀN THÀNH ---")