Modify

Opened 16 years ago

Closed 16 years ago

Last modified 16 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 Changed 16 years ago by Gary

  • Milestone set to 3.2.13.8
  • Owner set to Gary
  • Resolution set to Fixed
  • Status changed from new to closed

Fixed in version: 3.2.13.8

comment:2 Changed 16 years ago by PoorLuzer

This function seems to be buggy.

Discussion carried forward at:

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

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

Action
as closed The owner will remain Gary.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.