Jump to content

Problem with _FileReadToArray

Recommended Posts


Hi, I've got a problem.

My simple script is:

#include <File.au3>
#include <Array.au3>
$filein = "C:\test.txt"
Local $tablefromfile
_FileReadToArray($filein, $tablefromfile, Default, "|")

File test.txt:


When in file test.txt after "b" there is no "Enter" or there is one "Enter" - everything is OK,

but when there are more "Enter", or "Space" in the second line - didn't work. 


How can I read correctly file with many "Enter" after text?

Share this post

Link to post
Share on other sites


You are telling the function that it should split the lines on the "|" character - and so it does. You then add further lines which do not contain that character - and the function fails with @error 3 (you did test this yourself?) as explained in the Help file:



3 - File lines have different numbers of fields (only if $FRTA_INTARRAYS flag not set)


When a delimiter is specified the function tries to further split each line of the file - how this is done depends on the setting of the $FRTA_INTARRAYS flag. If the flag is not set and each line has the same number of fields split by the delimiter then a 2D array is created, but if this is not the case then @error is set to 3 and no array is returned

When used with the $sDelimiter parameter, the function expects a "square" file with each line having the same number of delimited items - in your case the lines do not meet this criterion and so the function fails.

You have 2 choices:

1. - Use the $FRTA_INTARRAYS  parameter to get an array of arrays - as explained in the Help file:


 If the $FRTA_INTARRAYS flag is set the function creates a 1D array where each element is a further array holding the fields of the line split on the delimiter - the lines do not need to have the same number of fields

2. - Do not use the $sDelimiter parameter and split each line individually when required.

Please ask if you have any further questions.


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:


ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area


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