Jump to content
Sign in to follow this  
igorm

_FileCountLines and AutoIt v3.2.13.9 (Beta) - BUG

Recommended Posts

igorm

Hi,

I want to report bug with latest AutoIt beta. When only one line is present in file, _FileCountLines will return 0 instead of 1. I really don't have time to go with bug report system, so I'm reporting here.

Cheers :mellow:

I edited function in latest beta so it works for me. I use old solution from latest stable version and solution from latest beta. Here it is:

Func _FileCountLines($sFilePath)
    Local $N = FileGetSize($sFilePath) - 1
;~  If @error Or $N = -1 Then Return 0
;~  Return StringLen(StringAddCR(FileRead($sFilePath, $N))) - $N + 1
    Local $hFile, $sFileContent, $aTmp
    $hFile = FileOpen($sFilePath, 0)
    If $hFile = -1 Then Return SetError(1, 0, 0)
    $sFileContent = StringStripWS(FileRead($hFile), 2)
    
    FileClose($hFile)
    If StringInStr($sFileContent, @CR) Then
        $aTmp = StringSplit(StringStripCR($sFileContent), @LF)
        
    ElseIf StringInStr($sFileContent, @CR) Then
        $aTmp = StringSplit($sFileContent, @CR)
    ElseIf Not $sFileContent = "" Then
        $aTmp=StringLen(StringAddCR(FileRead($sFilePath, $N))) - $N + 1
    Else
        Return SetError(2, 0, 0)
    EndIf
    If IsArray($aTmp) Then
    Return $aTmp[0]
Else
    Return $aTmp
    EndIf
EndFunc  ;==>_FileCountLines
Edited by igorm

Share this post


Link to post
Share on other sites
PsaltyDS

Confirmed issue is not present with 3.2.12.1 but is present with 3.2.13.9. Demo script:

#include <File.au3>
$sFile = _TempFile()
$hFile = FileOpen($sFile, 2)
FileWrite($hFile, "One line of text.")
FileClose($hFile)
ConsoleWrite("Count = " & _FileCountLines($sFile) & @LF)
FileDelete($sFile)

Terminating newline character doesn't matter as the result is the same with FileWriteLine() vice FileWrite().

:mellow:

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
GaryFrost

Try:

Func _FileCountLines($sFilePath)
    Local $hFile, $sFileContent, $aTmp
    $hFile = FileOpen($sFilePath, 0)
    If $hFile = -1 Then Return SetError(1, 0, 0)
    $sFileContent = StringStripWS(FileRead($hFile), 2)
    FileClose($hFile)
    If StringInStr($sFileContent, @LF) Then
        $aTmp = StringSplit(StringStripCR($sFileContent), @LF)
    ElseIf StringInStr($sFileContent, @CR) Then
        $aTmp = StringSplit($sFileContent, @CR)
    Else
        If StringLen($sFileContent) Then
            Return 1
        Else
            Return SetError(2, 0, 0)
        EndIf
    EndIf
    Return $aTmp[0]
EndFunc   ;==>_FileCountLines

If you don't have time to go into trac to report it, maybe I don't have time to fix it.

Edited by GaryFrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites
igorm

If you don't have time to go into trac to report it, maybe I don't have time to fix it.

I don't need your attitude. I have one of my own (bad attitude.)

BTW, thanks for new function. To bad you don't have time.

Cheers :mellow:

Share this post


Link to post
Share on other sites
igorm

Doubt this is considered funny.

You can consider what ever you want. I really appreciate what AutoIt developers do, but if I don't have the time to go with bug system, that does not mean that some developer should complain. Nobody force him to develop. What he wrote in his post sounded to me like he is complaining. I'm sorry if somebody is offended with my posts, that was not my intention.

Cheers :mellow:

Share this post


Link to post
Share on other sites
Jos

You can consider what ever you want. I really appreciate what AutoIt developers do, but if I don't have the time to go with bug system, that does not mean that some developer should complain. Nobody force him to develop. What he wrote in his post sounded to me like he is complaining. I'm sorry if somebody is offended with my posts, that was not my intention.

Cheers :mellow:

You sure have an arrogant approach here, but I am not going to spent more time on you as I don't care to much for people that want things to happen but "have no time" when they have to do something themselves.

Jos

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
igorm

You sure have an arrogant approach here, but I am not going to spent more time on you as I don't care to much for people that want things to happen but "have no time" when they have to do something themselves.

Jos

I don't see your point here. I don't want anything here to happen and I do things which I need myself. I even suggested temporary solution. What in your opinion do I need to do here?

Cheers :mellow:

Share this post


Link to post
Share on other sites
Josbe

I don't see your point here. I don't want anything here to happen and I do things which I need myself. I even suggested temporary solution. What in your opinion do I need to do here?

Cheers :(

Wasn't more easy/fast a report in trac than 3 replies in this thread? :mellow:

Suggestion: Next time, better use the Trac if you want benefit to Devs/community. Isn't obligatory, simply it's a better procedure.

Share this post


Link to post
Share on other sites
igorm

Wasn't more easy/fast a report in trac than 3 replies in this thread? :mellow:

Suggestion: Next time, better use the Trac if you want benefit to Devs/community. Isn't obligatory, simply it's a better procedure.

I agree. Now I have more time, but in the time I reported I was in hurry, so I just reported it so I don't forget it.

Cheers :(

Share this post


Link to post
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
Sign in to follow this  

×