Modify

Opened 18 years ago

Closed 18 years ago

Last modified 18 years ago

#506 closed Bug (Fixed)

_FileCountLines

Reported by: Xenobiologist Owned by: Gary
Milestone: 3.2.13.8 Component: AutoIt
Version: 3.2.13.7 Severity: None
Keywords: _FileCountLines Cc:

Description

Same problem as I mentioned before with _FileReadToArray.
The function _FileCountLines should deal all common line-end-chars.
LF, CR, CRLF.

I changed it to this:

; #FUNCTION# ====================================================================================================================
; Name...........: _FileCountLines
; Description ...: Returns the number of lines in the specified file.
; Syntax.........: _FileCountLines($sFilePath)
; Parameters ....: $sFilePath - Path and filename of the file to be read
; Return values .: Success - Returns number of lines in the file.
;                  Failure - Returns a 0
;                  @Error  - 0 = No error.
;                  |1 = File cannot be opened or found.
;                  |2 = Unable to Split the file
; Author ........: Tylo <tylo at start dot no>
; Modified.......: Xenobiologist
; Remarks .......: It does not count a final @LF as a line.
; Related .......:
; Link ..........;
; Example .......; Yes
; ===============================================================================================================================

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

Attachments (0)

Change History (2)

comment:1 by Gary, 18 years ago

Milestone: 3.2.13.8
Owner: set to Gary
Resolution: Fixed
Status: newclosed

Fixed in version: 3.2.13.8

comment:2 by PoorLuzer, 18 years ago

This function seems to be buggy.

Discussion carried forward at:

http://www.autoitscript.com/forum/index.php?showtopic=79656

Modify Ticket

Action
as closed The owner will remain Gary.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.