Code: Select all
Loop, Files, C:\*.txt
{
If IsAlpha(StrReplace(StrSplit(A_LoopFileName,".")[1],A_Space)){ ;if file name has no numbers or symbols...
FileRead, thisFile, % A_LoopFileFullPath
wordlist .= wordlist ? "`n" GetStringWordList(thisFile) : GetStringWordList(thisFile)
}
}
;MsgBox % finalWordList := GetStringWordList(wordList) ;sanitise wordlist for any duplicates during combining & remove any blank lines.
FileAppend, %finalWordList%, finalWordList.txt
GetStringWordList(text){ ;returns a list with no duplicates
StringReplace, text, text, `,, `n, ALL
StringReplace, text, text, `r`n, `n, ALL
StringReplace, text, text, %A_Space%, `n, ALL
StringReplace, text, text, %A_Tab%, `n, ALL
;remove white spaces
wordListText := RegExReplace(text , "(^|\R)\K\s+")
;rebuild wordlist using only strings longer than 3 characters
Wordlist:=""
Loop, Parse, wordListText, `n
If StrLen(A_LoopField) >= 1 ;strings of over 1 characters
IfNotInString, Wordlist, %A_Space%%A_LoopField%%A_Space% ;avoid repeated strings
Wordlist.= " " A_LoopField " " "`n" ;add spaces on either side so that words in other word can easily be added to list
StringReplace, Wordlist, Wordlist, %A_Space%, , ALL ;spaces are no longer needed as list is done building
Return WordList
}
IsAlpha(ByRef string){
If string is alpha
Return True
}