Modify

Opened 9 years ago

Closed 6 years ago

#1831 closed Bug (Fixed)

_FileCountLines does not handles null characters

Reported by: Fabien OBRIER <fobrier@…> Owned by:
Milestone: Component: AutoIt
Version: 3.3.6.1 Severity: None
Keywords: file.au3 _FileCountLines Cc:

Description

When using _FileCountLines on a text file containing some NULL (=Chr(0)) the function does not report the whole number of lines.
The function only return the number of lines before the first NULL character.

To avoid this, I propose to include a StrinReplace to delete the NULL characters as below:

Func _FileCountLines($sFilePath)

	Local $hFile = FileOpen($sFilePath, $FO_READ)
	If $hFile = -1 Then Return SetError(1, 0, 0)
	Local $sFileContent = StringStripWS(StringReplace(FileRead($hFile), Chr(0), ""), 2) ;****here is the modified line****
	FileClose($hFile)
	msgbox(0, "", $sFileContent)
	Local $aTmp
	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 

Best regards,
Fabien OBRIER

Attachments (1)

testNull.txt (74 bytes) - added by Fabien OBRIER <fobrier@…> 9 years ago.
sample txt file with NULL on line5

Download all attachments as: .zip

Change History (6)

Changed 9 years ago by Fabien OBRIER <fobrier@…>

sample txt file with NULL on line5

comment:1 Changed 9 years ago by Fabien OBRIER <fobrier@…>

Oups! In the script please ignore the line:

msgbox(0, "", $sFileContent)

comment:2 Changed 9 years ago by mvg

Problem is in the StringStripCR() function. Its clipping strings at the NUL-character. See ticket #1832

comment:3 Changed 8 years ago by Jon

  • Resolution set to Wont Fix
  • Status changed from new to closed

comment:4 Changed 6 years ago by Jpm

  • Resolution Wont Fix deleted
  • Status changed from closed to reopened

comment:5 Changed 6 years ago by Jpm

  • Resolution set to Fixed
  • Status changed from reopened to closed

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 ticket will remain with no owner.
Author


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

 
Note: See TracTickets for help on using tickets.