Not completed file reading - file-io

I'm trying to print the number of rows in my file training.txt but found out that my code does not read the whole file. Code goes like this:
row = 1
for line in io.lines 'training.txt' do
row = row + 1
end
print(row)
I tried changing the file with test.txt that has the same format with training.txt and file reading worked fine, reads until the end of file. So maybe the problem is with my text file? But how? It has the same format.
Text files are uploaded here for testing.

The file you uploaded training.txt is not the same format as test.txt, it does not have newline characters that indicate the EOL (End of Line). Try opening it in notepad to see the difference.

Related

How to append one text file to another text file

I need to append 1 text file to another text file.
I've done several keyword searches, and keep coming up with instructions on adding text to an existing file ... which is not the same as appending one text file to another text file.
In a well-designed language, it might look something like the line below, with the contents of source2 added to source1.
Append(path/source1, path/source2, ResultCode)

Vb.net What is the best way to parse a txt file that gets updated

what I need to accomplish: I need to read a text file that gets updated every 10 sec and dump the new data into. I need to find the best way to do this. I've tried streamreader and file.readalllines, I can get the contents of the txt file, but I don't know how to compare and dump the added lines. Any input would be appreciated, thank you.
Under the assumptions that this is a log file you're reading, where the data is being appended to end, and you're reading the file every 10 seconds, why don't you keep track of the number of lines read or the last line number from the last read?
You can then check to see whether the current read has exceeded the previous line number or number of lines read. If it has exceeded, you should be able to work out what the new lines were added because you know where you read until previously. You can read from the (previous read line + 1) until the end of file.

VBA Macros to open Multiple file path store in one cell

Could anyone help me with a macro that can open nultiple file path store in one cell
File path are stored in Column H and I
H1 can have file file path or multiple and same for I
For Example, if 1 file path is found, it will return as below
1,C:\Users\XXXX\Desktop\work\287497196_DN.pdf
And if 2 file path are stored, separted by a comma
2,C:\Users\XXXX\Desktop\work\Order_9250_TA_0580484707_Copy_of_del._note_XXX_signed_by_cust..TIF,C:\Users\XXXX\Desktop\work\Order_9250_TA_580484707_Customer_e-Mail.EML
The numbers in the start indicates the number of files found in a cell with file path
The files can be PDF, .TIf or .EML
Please help me how can I open all file if I click on that particular cell
Would be really helpful
Not have much time to write complete code, but try using something like:
newArray() = Split(Range("H1"), ",")
For i = 1 to Ubound(newArray)
Documents.Open newArray(i)
next i
So this will split your text with file paths using comma delimiter into an array.
After that you'll loop through array (note that 1st array element is zero, so that your loop starts from 2nd element)

VB.NET Append text to the end of a line in an exiting CSV file

How can I append text to the end a line in a text file with lines already there in VB.NET?
For example my text file looks like this:
header1,header2,header3
value1,value2,value3
stuff1,stuff2,stuff3
and I want to add new text to the end of each line so it looks like this:
header1,header2,header3,newheader
value1,value2,value3,newvalue
stuff1,stuff2,stuff3,newstuff
I know that in Perl you can point to the line and then act on it, is there some VB.net way to do this?
If the file isn't too big, the simplest is, probably, to use the IO.File.ReadAllLines method to read the file into memory and modify the data and write it back with the WriteAllLines method.
For very large files you're probably looking at reading each line modifying it and writing it to a different file.

Redis how to write binary data to dump file?

I want to know REDIS how to write binary data.
It open a file not in "b" mode.
fp = fopen(tmpfile,"w")
Any help in this regard.
In liunx, fopen has no b mode, see fopen man doc:
r Open text file for reading. The stream is positioned at the beginning of the file.
r+ Open for reading and writing. The stream is positioned at the beginning of the file.
w Truncate file to zero length or create text file for writing. The stream is positioned at the beginning of the file.
w+ Open for reading and writing. The file is created if it does not exist, otherwise it is truncated. The stream is positioned at the beginning of the file.
a Open for appending (writing at end of file). The file is created if it does not exist. The stream is positioned at the end of the file.
a+ Open for reading and appending (writing at end of file). The file is created if it does not exist. The initial file position for reading is at the beginning of the file,
but output is always appended to the end of the file.