2
Answers

End of File

Photo of steven.schwartz

steven.schwartz

21y
1.7k
1
is there a property in the .net that will let me know how many fields (rows) are in a text file?

Answers (2)

0
Photo of itsMahesh82
NA 4 0 21y
Hello, Let me know that How is ur txt file? Is ur txt file is comma separated..or anything? Thanks...
0
Photo of spgilmore
NA 591 0 21y
The OS doesn't know how many lines there are without scanning the entire file to count the line breaks. It DOES, however, know how many bytes are in the file IF the file is opened as a binary file. If you want to know how many lines, you'll have to read the file and count them. This is the case with C++, VB6, QuickBasic, TurboPascal, Delphi, etc. It's the nature of text files. If you want to present a progress bar as you read the file, you may first open the file using a FILESTREAM and get the byte size, and close the file. Then open it as a streamreader and read each line. As you read each line, count the bytes in the string and add it to your total (+2 for the linebreak). It's not always 100% because of the line breaks, but it's good enough for a progress bar if the file is really that big. If neither of these solutions are acceptable, you have other options if you're creating this file. You need to either store the offset of each line in a separate file, or make the lines all the same (known) size so that you can divide the size of the file by the line size to get the line count. If you're clever you can come up with others, but it depends on what you're trying to do.