Zeerti Posted April 29, 2014 Share Posted April 29, 2014 (edited) I am working on creating a script to notify me when something is said in my works chat room. I think I am not understanding how FileReadLine and OpenFile work in tandem and this is why it's always returning a blank for $LineRead. Could someone point out to me the error in my code OR a better way to implement this? The next nightmare is the regular expression to parse it out. :/ one step at a time tho! $FileList = _FileListtoArrayEx('C:\Users\Zoidberg\AppData\Roaming\.purple\logs\jabber\***', '*.*', 1) $File = $FileList[$FileList[0]] ;get newest log file while true ;Array of files in log folder ;_ArrayDisplay($FileList, "File List") $FileHandle = FileOpen($File, 1) if @error then ; MsgBox($MB_SYSTEMMODAL, "Error", "Failure to open file" ; endif $LineRead = FileReadLine($FileHandle, -1) if @error then ; MsgBox($MB_SYSTEMMODAL, "Error", "Failure to read file") ; endif FileClose($FileHandle) MsgBox($MB_OK, "TEST", $LineRead) WEND Edited April 29, 2014 by Zeerti Link to comment Share on other sites More sharing options...
somdcomputerguy Posted April 29, 2014 Share Posted April 29, 2014 $FileHandle = FileOpen($File, 1)You're opening the file for writing.. Replace the 1 (write mode) with a 0 (read mode), or specify nothing as 0 is the default. - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
Zeerti Posted April 29, 2014 Author Share Posted April 29, 2014 I actually tried doing it that way and it still was failing, I'll try specifically giving it a zero though. Link to comment Share on other sites More sharing options...
Zeerti Posted April 30, 2014 Author Share Posted April 30, 2014 In fact when I set it to 0 for the FileOpen( ) it sets the error flag for FileReadLine and then that doesn't work. Link to comment Share on other sites More sharing options...
somdcomputerguy Posted April 30, 2014 Share Posted April 30, 2014 _FileListtoArrayEx('C:\Users\Zoidberg\AppData\Roaming\.purple\logs\jabber\***', '*.*', 1)What is the _FileListtoArrayEx()function, and what are the three asterisks at the end of the first parameter? - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
AndrewG Posted April 30, 2014 Share Posted April 30, 2014 Hello, This script shows how to get a list of all files with a .log file extension located in a Temp folder on the C: drive. It will then open the last file in the returned array (File List) and read the last line in that file and show it in a msgbox. You will have to change the file path for the _FileListToArray() function to point to your log files, and change the filter if needed. This script should get you started . #include <File.au3> #include <Array.au3> #include <MsgBoxConstants.au3> Global $aFileList, $sNewestLogFile, $hFileOpen, $sLine ;Get list of Files $aFileList = _FileListToArray("C:\Temp\", "*.log", 1, 1) ;Get path to last file in the array(File list). - (Assuming that the last file is the newest) $sNewestLogFile = $aFileList[$aFileList[0]] ;Open the file for reading. $hFileOpen = FileOpen($sNewestLogFile, 0) ;Read last line in file. $sLine = FileReadLine($hFileOpen, -1) ;Close the open file. FileClose($hFileOpen) ;Display the line. Msgbox($MB_SYSTEMMODAL,"",$sLine) Link to comment Share on other sites More sharing options...
Zeerti Posted April 30, 2014 Author Share Posted April 30, 2014 _FileListtoArrayEx('C:\Users\Zoidberg\AppData\Roaming\.purple\logs\jabber\***', '*.*', 1) What is the _FileListtoArrayEx()function, and what are the three asterisks at the end of the first parameter? the asterisks are me just censoring things. Hello, This script shows how to get a list of all files with a .log file extension located in a Temp folder on the C: drive. It will then open the last file in the returned array (File List) and read the last line in that file and show it in a msgbox. You will have to change the file path for the _FileListToArray() function to point to your log files, and change the filter if needed. This script should get you started . #include <File.au3> #include <Array.au3> #include <MsgBoxConstants.au3> Global $aFileList, $sNewestLogFile, $hFileOpen, $sLine ;Get list of Files $aFileList = _FileListToArray("C:\Temp\", "*.log", 1, 1) ;Get path to last file in the array(File list). - (Assuming that the last file is the newest) $sNewestLogFile = $aFileList[$aFileList[0]] ;Open the file for reading. $hFileOpen = FileOpen($sNewestLogFile, 0) ;Read last line in file. $sLine = FileReadLine($hFileOpen, -1) ;Close the open file. FileClose($hFileOpen) ;Display the line. Msgbox($MB_SYSTEMMODAL,"",$sLine) This is exactly what I was trying to do with the same functions and stuff. I'll give this a try and see what happens. Much appreciated! Link to comment Share on other sites More sharing options...
somdcomputerguy Posted April 30, 2014 Share Posted April 30, 2014 the asterisks are me just censoring things.Oh, OK. - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
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