AutoItSetOption ( "MouseCoordMode", 2)
AutoItSetOption ( "PixelCoordMode", 2)
; Shows the filenames of all files in the current directory
$dir = @ScriptDir & "\text\"
FileChangeDir($dir)
DirCreate($dir & "ok\")
processdir("*.txt",$dir)
processdir("*.doc",$dir)
processdir("*.docx",$dir)
Func processdir($pattern,$dir)
$search = FileFindFirstFile($pattern)
; Check if the search was successful
If $search = -1 Then
Return
EndIf
While 1
$file = FileFindNextFile($search)
If @error Then ExitLoop
$text = get_file_contents($dir & $file)
$text = StringRegExpReplace($text,"(?s)<STYLE[^>]*>.*</STYLE>","")
$text = StringRegExpReplace($text,"<[^<]*>","")
$text = StringReplace($text," "," ")
$text = StringReplace($text,"–","-")
$length = StringLen($text)
$unq = checkuniq($text)
$new_name = "ok\" & StringFormat("%03d%% - %05d chars ",$unq,$length) & "-" & $file
FileMove($file,$new_name,8)
WEnd
FileClose($search)
EndFunc
Func get_file_contents($filename)
Local $oWord , $oWordDocuments , $oWordDocument ,$oWordContent ,$TextDoc
$ext = CompGetFileExt($filename)
Switch $ext
Case ".txt"
return FileRead($filename);
Case Else
$oWord = ObjGet("","Word.Application") ; Connect to Word > Receive a Wordd Object
if @error then
$oWord = ObjCreate("Word.Application")
EndIf
$oWord.Visible = 1 ; Ask to Show Word
$oWordDocuments = $oWord.Documents ; Ask the Word Object to Receive a Collection of Documents
$oWordDocument = $oWordDocuments.Open($filename) ; Open the file MyDoc.doc, add it to to the Collection and receive the Object
$oWordContent = $oWorddocument.Content ; Ask to Receive the Contents Object of the Object Document
$TextDoc = $oWordContent.Text ; Ask to Extract the Text of the Contents Object in an AutoIt Variant
$oWordDocument.Close
$oWordDocument = 0
$oWord = 0
return $TextDoc
EndSwitch
return ""
EndFunc
Func CompGetFileExt($Path,$Dot=True)
If StringLen($Path) < 4 Then Return -1
$ret = StringSplit($Path,"\",2)
If IsArray($ret) Then
$ret = StringSplit($ret[UBound($ret)-1],".",2)
If IsArray($ret) Then
If $Dot Then
$Dot = "."
Else
$Dot = ""
EndIf
Return $Dot & $ret[UBound($ret)-1]
EndIf
EndIf
If @error Then Return -1
EndFunc
Func checkuniq($thetext)
Local $reslt
Local $testok
Local $pos1
Local $pc
ControlSetText("Advego Plagiatus","","[CLASS:ATL:00669668; INSTANCE:1]",$thetext)
WinActivate("Advego Plagiatus")
MouseClick("left",175, 41)
WinWait("Проверка документа")
While 1
Sleep(1000)
$reslt = WinGetText("Проверка документа","")
$testok = StringRegExp($reslt,"Уникальность текста [0-9]+%")
if $testok = 1 Then
$pos1 = StringInStr($reslt,"текста ")
$pc = StringMid($reslt,$pos1+7,5)
$pos1 = StringInStr($pc,"%")
$pc = StringLeft($pc,$pos1-1)
WinActivate("Проверка документа")
MouseClick("left",54, 147)
WinWaitClose("Проверка документа")
Return $pc
EndIf
$testok = StringRegExp($reslt,"Уникальность документа не определена")
if $testok = 1 Then
WinActivate("Проверка документа")
MouseClick("left",54, 147)
WinWaitClose("Проверка документа")
Return 0
EndIf
WEnd
EndFunc