File Size in VB for Windows XP
Frecuentes
Visto 2,536 veces
2
Hi this might sound weird, below is my VB Code
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
This script shows the value '6' for 6bytes as the file size in Windows 7 but in XP it shows 0 even though the file size is 6 bytes .... any ideas ?
EDIT:
I figured it out, had to close the file first and then display the filesize.size for XP to display the proper file size.
Still don't know why this works on windows 7 ... any thoughts ?
1 Respuestas
2
My best guess would be a change to file caching between the two versions of windows or the FileSystemObject
http://msdn.microsoft.com/en-us/library/windows/desktop/aa364218%28v=vs.85%29.aspx
Según http://msdn.microsoft.com/en-us/library/z9ty6h50%28v=vs.84%29.aspx
The Close method flushes the buffer and closes the file.
So the XP version isn't seeing the file size until the IO is flushed to the disk.
Respondido 24 ago 12, 00:08
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas file vbscript windows-xp size or haz tu propia pregunta.
this looks like VBScript, not VB.NET. Please retag. - Sam Axe
Corrections made ... so any thought as to why the size is retrieved in windows 7 before even closing 'filewrt' and not in XP? - Telson Alva
@asawyer's answer seems feasible. - Sam Axe