Last active
August 8, 2024 05:25
-
-
Save CodeCouturiers/4cccac64ca84feb1a3856e8b81757f11 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import re | |
def find_cyrillic_in_files(directory, extensions): | |
# Регулярное выражение для поиска кириллических букв | |
cyrillic_pattern = re.compile(r'[А-Яа-яЁё]') | |
# Обход всех файлов в директории | |
for root, _, files in os.walk(directory): | |
for file in files: | |
# Проверяем расширение файла | |
if file.endswith(extensions): | |
file_path = os.path.join(root, file) | |
try: | |
with open(file_path, 'r', encoding='utf-8') as f: | |
lines = f.readlines() | |
for line_number, line in enumerate(lines, start=1): | |
# Поиск кириллических букв в строке | |
matches = cyrillic_pattern.findall(line) | |
if matches: | |
# Выводим номер строки и совпадения | |
print(f'Кириллические буквы найдены в файле {file_path}, строка {line_number}: {line.strip()}') | |
except (UnicodeDecodeError, FileNotFoundError, PermissionError) as e: | |
print(f'Не удалось прочитать файл {file_path}: {e}') | |
# Укажите путь к директории и интересующие расширения файлов | |
directory_path = r'..........' | |
file_extensions = ('.txt', '.md', '.cs') # Замените или добавьте расширения по вашему усмотрению | |
find_cyrillic_in_files(directory_path, file_extensions) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment