import re | |
from pathlib import Path | |
# データセットのタグからユーザーネームを検知した時にアラートする | |
def check_tags(directory_path): | |
dir_path = Path(directory_path) | |
username_pattern = re.compile(r'(username|user_name)', re.IGNORECASE) | |
for file_path in dir_path.glob('*.txt'): | |
with open(file_path, 'r') as f: | |
tags = f.read().replace(" ", "").strip().split(',') | |
for tag in tags: | |
if username_pattern.search(tag): | |
print(f"Warning: File {file_path.name} contains tag: {tag}") | |
if __name__ == "__main__": | |
directory_path = r"E:\Dataset\XXXXXX" # ここにディレクトリへのパスを入力してください | |
check_tags(directory_path) | |