face Posted December 30, 2013 Posted December 30, 2013 how can i extract words from text files and save them as a list. program gets access to the folder that contains the text files (more than 2 text files) reads all the text files contents ignores special characters and numbers extracts all words (no duplicates) saves all extracted words in a .txt file as a list textfilefolder.rar
JohnOne Posted December 30, 2013 Posted December 30, 2013 Define "words" Is bbfgytwxv a word? AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
face Posted December 30, 2013 Author Posted December 30, 2013 words are sepearated by spaces, even made up words count
JohnOne Posted December 30, 2013 Posted December 30, 2013 Then FileRead() and StringSplit() should get you started. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
jchd Posted December 30, 2013 Posted December 30, 2013 Adapt this to your context: #include <File.au3> #include <Array.au3> Local $oDictionary = ObjCreate("Scripting.Dictionary") Local $mypath = @ScriptDir Local $aFiles = _FileListToArray($mypath, "*.txt", 1, 1) Local $aWords For $i = 1 To $aFiles[0] $aWords = StringRegExp(FileRead($aFiles[$i]), "\w+", 3) ; change pattern to fit your definition of "word" For $Word In $aWords $oDictionary.ADD($Word, $Word) Next Next $aWords = $oDictionary.Items FileWrite("words.txt", _ArrayToString($aWords, @CRLF)) ConsoleWrite($oDictionary.Count & " words found in " & $aFiles[0] & " files." & @LF) This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
face Posted December 30, 2013 Author Posted December 30, 2013 (edited) Adapt this to your context: #include <File.au3> #include <Array.au3> Local $oDictionary = ObjCreate("Scripting.Dictionary") Local $mypath = @ScriptDir Local $aFiles = _FileListToArray($mypath, "*.txt", 1, 1) Local $aWords For $i = 1 To $aFiles[0] $aWords = StringRegExp(FileRead($aFiles[$i]), "\w+", 3) ; change pattern to fit your definition of "word" For $Word In $aWords $oDictionary.ADD($Word, $Word) Next Next $aWords = $oDictionary.Items FileWrite("words.txt", _ArrayToString($aWords, @CRLF)) ConsoleWrite($oDictionary.Count & " words found in " & $aFiles[0] & " files." & @LF) theres 1 error i cant fix it Edited December 30, 2013 by face
Moderators Melba23 Posted December 30, 2013 Moderators Posted December 30, 2013 face,That syntax uses the new v3.3.10.# version of the function. If you have not yet updated (which from the error would seem to be the case) then change the line to read: Local $aFiles = _FileListToArray($mypath, "*.txt", 1)M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
face Posted December 30, 2013 Author Posted December 30, 2013 i updated autoit version now i get another error
jchd Posted December 30, 2013 Posted December 30, 2013 As you can see I omitted every error checking. Most probably no file match your search. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
Moderators Solution Melba23 Posted December 30, 2013 Moderators Solution Posted December 30, 2013 face,Then we need to add some errorchecking code to see where the problem lies: #include <File.au3> #include <Array.au3> #include <MsgBoxConstants.au3> Local $oDictionary = ObjCreate("Scripting.Dictionary") Local $mypath = @ScriptDir Local $aFiles = _FileListToArray($mypath, "*.au3", 1, 1) If @error Then MsgBox($MB_SYSTEMMODAL, "Error", "No files found") Exit Else MsgBox($MB_SYSTEMMODAL, "Found", $aFiles[0] & " files") EndIf Local $aWords For $i = 1 To $aFiles[0] $aWords = StringRegExp(FileRead($aFiles[$i]), "\w+", 3) ; change pattern to fit your definition of "word" Local $iError = @error If $iError = 0 Then For $Word In $aWords $oDictionary.ADD($Word, $Word) Next Else MsgBox($MB_SYSTEMMODAL, "Error", $aFiles[$i] & " - " & $i & @CRLF & "error: " & $iError) EndIf Next $aWords = $oDictionary.Items FileWrite("words.txt", _ArrayToString($aWords, @CRLF))What error MsgBoxes do you get - if any? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
jdelaney Posted December 30, 2013 Posted December 30, 2013 (edited) Might want to look into only skipping spaces...(grabs special chars, that way...but then again, might not be what you expect...example: would return appostrophes ) $aWords = StringRegExp(FileRead($aFiles[$i]), "[^\s]+", 3) or only including non spaces... $aWords = StringRegExp(FileRead($aFiles[$i]), "\S+", 3) Edited December 30, 2013 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now