如何在FSO模型下确定文本文件中的位置? [英] How to determine position within a text file under FSO model?
问题描述
大家好。
过去我使用旧的内置VB语句完成了大部分文件IO,例如打开,行输入#,获取,放置等。在最近的一个项目中,我决定尝试更新一下,所以我使用 File 对象来表示每个文件,然后使用 OpenAsTextStream 来创建 TextStream 对象,然后使用 ReadLine 读取它。
除了一件事之外,它的工作正常。我如何知道我在文件中的位置?我正在处理大文件(数百MB)所以我想提供一个进度指示器,根据文件大小和我在文件中的位置。之前使用LOF和Seek函数非常简单。但是当以这种方式使用TextStream时,我如何确定我当前的位置?我当然可以得到行号,但为了这个用途,我需要知道总行数。
目前我刚开始做一个完整的阅读通过文件(使用 .ReadLine )来计算行数。这相当快(任何时间从5到30秒),然后我可以使用该计数在真实期间提供进度指示器。处理(显然需要更长时间,或者我不会打扰)。但是像这样对文件进行双重传递似乎很愚蠢。
Hi all.
In the past I''ve done most file IO using the old built-in VB statements such as Open, Line Input #, Get, Put and so on. In a recent project I decided to try and update a bit, so I''m using a File object to represent each file, and OpenAsTextStream to create a TextStream object, then reading that using ReadLine.
It''s working just fine, except for one thing. How can I tell where I am in the file? I''m dealing with large files (hundreds of MB) so I like to provide a progress indicator, based on the file size and my position in the file. That was perfectly simple before, using LOF and Seek functions. But when using a TextStream in this way, how can I determine my current position? I can get the line number of course, but for that to be any use I need to know the total number of lines.
At the moment I just start out by doing a complete read through the file (using .ReadLine) to count the lines. This is fairly quick (anywhere from 5 to 30 seconds), then I can use that count to provide the progress indicator during the "real" processing (which obviously takes much longer, or I wouldn''t bother). But it seems silly to have to do a double pass through the file like this.
推荐答案
你好,
你想添加一个吗?进度条或任何滑块类型的东西。
Hello,
Do you want to add a progressbar or any slider type thing.
几天前我已经回答了这个问题。
使用ReadAll方法和分割为vbCrLF,你将得到数组'的ubound作为行数..:
Hi,
I had answered this a few days ago.
Use "ReadAll" Method, and Split for vbCrLF, you will get Array''s ubound as No. of Lines..:
使用ReadAll方法,并为vbCrLF拆分,你将得到数组'的ubound作为行数..:
Use "ReadAll" Method, and Split for vbCrLF, you will get Array''s ubound as No. of Lines..:
感谢你的想法。
我宁愿不要。我已经在计算行数,所以我不需要这样做(尽管你的速度可能更快)。由于每个文件的大小至少为100-200MB,我不想在我的RAM上复制它。这就是为什么我要逐行处理它。
Thanks for the idea.
I''d rather not, though. I am already counting the number of lines, so I don''t need a way to do that (though yours may be faster). Since each file is at least 100-200MB in size, I don''t want to be making copies of it all over my RAM. That''s why I''m processing it line by line.
这篇关于如何在FSO模型下确定文本文件中的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!