;в эту строку можно добавить свои пары символов (ЮZжF) которые нужно заменить
;где ПЕРВЫЙ символ будет заменен на ВТОРОЙ ТРЕТИЙ на ЧЕТВЕРТЫЙ и т.д.
;пары можно не разделять или разделять любыми не буквенными символами
$sChars = 'ЕE еe гr ТT уy иu ОO оo РP рp КK кk НH дg аa АA хx ХX сc СC ьb ВB пn тm МM з3 З3 ч4 Ч4 шw ШW щw ЩW'
;здесь указываете путь к папке где лежат файлы которые нужно обработать
$sFoderIn = @ScriptDir& '\Новая папка'
;это путь к папке куда ложить измененные файлы и логи работы
$sFoderOut = @ScriptDir& '\ReplaceCyrillic'
;режим кодировки файла (возможные значения как у FileOpen() функции)
$iMode = 2 +8
Recursion_($sFoderIn)
Func Recursion_($_sFoder)
Local $sWordsRusCyrillic, $sWordsChanged, $_sText, $_sWord, $_aAllWords, $_iA, $_iLog, $_sNewFile, $_sAllWorlds ='|', $_iCounter
Local $_hList=FileFindFirstFile($_sFoder& '\*.*')
While 1
$_sFile=FileFindNextFile($_hList)
If @error Then
ExitLoop
EndIf
If @extended Then
Recursion_($_sFoder& '\'& $_sFile)
ElseIf $_sFile <> @ScriptName Then
$_iLog = 0
$_sAllWorlds = '|'
$_sWordsRusCyrillic = ''
$_sWordsChanged = ''
$_sText = FileRead($_sFoder& '\'& $_sFile)
$_aAllWords = StringRegExp($_sText, '(?i)([A-Za-zА-Яа-яЁё0-9]+).?', 3)
If Not @error Then
For $_iA = 0 To UBound($_aAllWords) -1
If Not StringInStr($_sAllWorlds, '|'& $_aAllWords[$_iA]& '|') Then
If Not WordIsEng_($_aAllWords[$_iA]) Then
If Not WordIsRus_($_aAllWords[$_iA]) Then
$_iLog = 1
$_sWord = ReplaceCyrillic_($_aAllWords[$_iA])
If WordIsEng_($_sWord) Then
$_sText = StringReplace($_sText, $_aAllWords[$_iA], $_sWord)
$_iCounter = @extended
$_sWordsChanged &= $_aAllWords[$_iA]& ' > '& $_sWord& ' < ['& $_iCounter& ']'& @CRLF
Else
$_sWordsRusCyrillic &= $_aAllWords[$_iA]& @CRLF
EndIf
EndIf
EndIf
$_sAllWorlds &= $_aAllWords[$_iA]& '|'
EndIf
Next
If $_iLog Then
$_sNewFile = StringReplace($_sFoder, $sFoderIn, $sFoderOut)
DirCreate($_sNewFile)
$_sNewFile &= '\'& $_sFile
$hF=FileOpen($_sNewFile, $iMode)
FileWrite($hF, $_sText)
FileClose($hF)
If $_sWordsChanged <> '' Then
FileWrite($_sNewFile& '.log', 'Слова которые были заменены (Оригинал > Замена < [Кол-во замен]):'& @CRLF& @CRLF)
FileWrite($_sNewFile& '.log', $_sWordsChanged& @CRLF& @CRLF)
EndIf
If $_sWordsRusCyrillic <> '' Then
FileWrite($_sNewFile& '.log', 'Слова которые все еще содержат русские буквы:'& @CRLF& @CRLF)
FileWrite($_sNewFile& '.log', $_sWordsRusCyrillic& @CRLF& @CRLF)
FileWrite($_sNewFile& '.log', 'Для их замены в дальнейшем нужно в скрипте в переменной $sChars добавить какую букву на какую заменить.'& @CRLF)
EndIf
EndIf
EndIf
EndIf
WEnd
EndFunc
Func WordIsEng_($_sWord)
StringRegExpReplace($_sWord, '[А-Яа-яЁё]', '')
Return (@extended = 0)
EndFunc
Func WordIsRus_($_sWord)
StringRegExpReplace($_sWord, '[^А-Яа-яЁё0-9]', '')
Return (@extended = 0)
EndFunc
Func ReplaceCyrillic_($_sText)
Local Static $_aChars = CharsSplitPairs_($sChars)
Local $_iA, $_sReplaceable, $_sReplacing
For $_iA = 1 To $_aChars[0]
$_sReplaceable = StringRegExpReplace($_aChars[$_iA], '(.)(.)', '$1')
$_sReplacing = StringRegExpReplace($_aChars[$_iA], '(.)(.)', '$2')
$_sText = StringRegExpReplace($_sText, $_sReplaceable, $_sReplacing)
Next
Return $_sText
EndFunc
;ФУНКЦИЯ РАЗБИВАЕТ СТРОКУ НА МАСИВ, СОДЕРЖАЩИЙ В СЕБЕ ПАРЫ СИМВОЛОВ
;----------------------------------------------------------------------------------------------
;Например строка
;$_sChars = EЕrгTТ
;примет вид масива:
;$Array[0] = EЕ
;$Array[1] = rг
;$Array[2] = TТ
;----------------
;При параметре $_iLen = 0
;масив будет иметь вид как выше
;а при $_iLen = 1
;$Array[0] = 3
;$Array[1] = rг
;$Array[2] = TТ
;$Array[3] = EЕ
;где $Array[0] = 3 это кол-во элементов в масиве
Func CharsSplitPairs_($_sChars, $_iLen = 1)
Local $_sPairs = StringRegExp($_sChars, '[A-Za-zА-Яа-яЁё]{2}', 3)
If @error Then
Return SetError(1)
EndIf
If $_iLen Then
$_iLen = UBound($_sPairs)
ReDim $_sPairs[$_iLen +1]
$_sPairs[$_iLen] = $_sPairs[0]
$_sPairs[0] = $_iLen
EndIf
Return $_sPairs
EndFunc