嗨,这可能听起来很奇怪,下面是我的 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/