Vbscript 寻找文件末尾以制作尾部命令脚本 [英] Vbscript seek to end of file to make a tail command script

查看:20
本文介绍了Vbscript 寻找文件末尾以制作尾部命令脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 vbscript 编写了一个简单的 tail 命令.它工作正常,除了非常大的文件,它必须通读整个文件才能获得最后 10 行.有没有办法搜索到文件末尾然后向后读取十行?

I've writen a simple tail command using vbscript. It works fine except for very large files where it has to read through the entire file to get the last 10 lines. Is there a way to seek to the end of the file and then read backwards for ten lines?

推荐答案

恐怕在 VBS TextStream 中向后查找是不可能的,但是您可以查找到一个位置,而不是通读整个文件,例如.EOF 前 1K,然后读取文件的其余部分,仅显示最后 10 行.

I am afraid that seeking backwards is impossible in VBS TextStream, but instead of reading through the entire file you can seek to a position eg. 1K before EOF and then read the rest of the file, displaying only the last 10 lines.

我添加了一些示例代码来说明这个想法:

I'm adding some sample code to illustrate the idea:

set fso = CreateObject("Scripting.FileSystemObject")
set file = fso.GetFile(filePath)
set stream = file.OpenAsTextStream(1, -2)
pos1KBeforeEnd = file.Size-1024
if pos1KBeforeEnd<0 then pos1KBeforeEnd=0
stream.Skip pos1KBeforeEnd

这篇关于Vbscript 寻找文件末尾以制作尾部命令脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆