File Size in VB for Windows XP

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 ?

preguntado el 24 de agosto de 12 a las 00:08

this looks like VBScript, not VB.NET. Please retag. -

Corrections made ... so any thought as to why the size is retrieved in windows 7 before even closing 'filewrt' and not in XP? -

@asawyer's answer seems feasible. -

1 Respuestas

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 or haz tu propia pregunta.