Modify

Opened 15 years ago

Closed 13 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@…> 15 years ago.
sample txt file with NULL on line5

Download all attachments as: .zip

Change History (6)

by Fabien OBRIER <fobrier@…>, 15 years ago

Attachment: testNull.txt added

sample txt file with NULL on line5

comment:1 by Fabien OBRIER <fobrier@…>, 15 years ago

Oups! In the script please ignore the line:

msgbox(0, "", $sFileContent)

comment:2 by mvg, 15 years ago

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

comment:3 by Jon, 15 years ago

Resolution: Wont Fix
Status: newclosed

comment:4 by J-Paul Mesnage, 13 years ago

Resolution: Wont Fix
Status: closedreopened

comment:5 by J-Paul Mesnage, 13 years ago

Resolution: Fixed
Status: reopenedclosed

Modify Ticket

Action
as closed The ticket will remain with no owner.

Add Comment


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