Sign in to follow this  
Followers 0
trids

Udf _filereadtoarray

1 post in this topic

Here's Larry's :whistle: UDF (hope you don't mind, Larry?)...

;===============================================================================
;
; Description:      Reads the specified file into an array.
; Syntax:           _FileReadToArray( $sFilePath, $aArray )
; Parameter(s):     $sFilePath - Path and filename of the file to be read
;                   $aArray    - The array to store the contents of the file
; Requirement(s):   None
; Return Value(s):  On Success - 1
;                   On Failure - 0 and sets @ERROR = 1
; Author(s):        Jonathan Bennett <jon at hiddensoft com>
; Note(s):          None
;
;===============================================================================
Func _FileReadToArray( $sFilePath, ByRef $aArray )
;==============================================
; Local Constant/Variable Declaration Section
;==============================================
 Local $hFile
   
 $hFile = FileOpen( $sFilePath, 0 )

 If $hFile = -1 Then
   SetError( 1 )
   Return 0
 EndIf

 $aArray = StringSplit( StringStripCR( FileRead( $hFile, _
                 FileGetSize( $sFilePath ) ) ), @LF )

 FileClose( $hFile )

 Return 1
EndFunc

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  
Followers 0