javascript vbscript 寻找 eof

发布于 2024-08-21 00:01:57 字数 197 浏览 4 评论 0原文

我正在 Windows 2003 上编写 destop 脚本,我需要打开一个文件并查找它的末尾并读取最后一行。 我寻找“寻找”,但没有找到。我看到了 openTextFile 选项,但没有。

我通过打开带有红旗的文件然后逐行读取来实现它。 对于大文件,需要花费一些时间,

有谁知道如何快速完成此操作(在 vb 脚本或 javascript 中)

I am writing a destop script on windows 2003 and I need to open a file and seek to the end of it and read the last line.
I looked for a "seek" but couldn't find. I saw the openTextFile for option but didn't have.

I implement it by openning the file with the red flag and then reading line after line.
With big file it takes a time,

Do any one know how to do this quickly (either in vb script or javascript)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

和影子一齐双人舞 2024-08-28 00:01:58

我想不出一种简单的方法来做到这一点,除了读取整个文件,分成一个数组并弹出最后一行:

var fso   = new ActiveXObject("Scripting.FileSystemObject");
var tf    = fso.OpenTextFile("c:\\testfile.txt", 1 /*for reading*/, false);

// Split all lines into an array
var lines = tf.ReadAll().split("\r\n");

// Get the last line from the file:
var lastLine = lines.pop();

我已经在很多情况下这样做了,它应该比循环更快。

I can't think of a straightforward way to do it except for maybe reading the whole file, splitting into an array and popping the last line off:

var fso   = new ActiveXObject("Scripting.FileSystemObject");
var tf    = fso.OpenTextFile("c:\\testfile.txt", 1 /*for reading*/, false);

// Split all lines into an array
var lines = tf.ReadAll().split("\r\n");

// Get the last line from the file:
var lastLine = lines.pop();

I've done this on a number of occasions and it should be faster than a loop.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文