Windows XP 中 VB 中的文件大小

标签 file vbscript windows-xp size

嗨,这可能听起来很奇怪,下面是我的 VB 代码

Const ForReading = 1, ForWriting = 2, ForAppending = 8

Set filesys = CreateObject("Scripting.FileSystemObject")
'Set fileapp = filesys.OpenTextFile("C:\TEST.txt", ForAppending, True) 
Set filewrt = filesys.OpenTextFile("C:\TEXT.txt", ForWriting, True) 
Set filesize = filesys.GetFile("C:\TEXT.txt")


filewrt.Write("HELOOO")
msgbox filesize.size
filewrt.close

此脚本在 Windows 7 中显示 6 字节的值“6”作为文件大小,但在 XP 中,即使文件大小为 6 字节,它也显示 0 ....有什么想法吗?

编辑:

我想通了,必须先关闭文件,然后显示文件大小。XP 才能显示正确的文件大小。

仍然不知道为什么这在 Windows 7 上有效......有什么想法吗?

最佳答案

我最好的猜测是在两个版本的 Windows 或 FileSystemObject 之间更改文件缓存

http://msdn.microsoft.com/en-us/library/windows/desktop/aa364218%28v=vs.85%29.aspx

根据http://msdn.microsoft.com/en-us/library/z9ty6h50%28v=vs.84%29.aspx

The Close method flushes the buffer and closes the file.

因此,XP 版本在 IO 刷新到磁盘之前无法看到文件大小。

关于Windows XP 中 VB 中的文件大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12101229/

相关文章:

php - 确保所有文件具有唯一名称的正确方法?

c - 如何在c中获取文件长度?

c# - 注册表观察程序C#实现RegistryKeyChangeEvent

windows - 如何加速 Windows XP 应用程序中的 UDP 通信

file - 滚动平面文件日志文件未正确滚动

php - 使用 vfsStream 测试 move_uploaded_file 和 is_uploaded_file

vbscript - Asp 经典格式数字不显示最后的零

javascript - 使用 VBScript.ASP 和 JavaScript 在提交 FormA 的同时提交 FormB

Scripting.Dictionary Lookup-add-if-not-present 只有一键搜索?

printing - 使用 Windows 图片和传真查看器 (shimgvw.dll) 从命令行打印 jpg 时,如何选择布局?