Jump to content

FileReadLine Returning Blank


Recommended Posts

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 by Zeerti
Link to comment
Share on other sites

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

_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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...