Jump to content
Sign in to follow this  
stampy

FileGetSize not responding correct in Vista

Recommended Posts

stampy

One of my scripts is not running correctly under Vista. It simply downloads a file then while the file is downloading reports the file size. After some research I've found that the FileGetSize function seems to not work correctly in Vista. In XP it works fine. But in Vista it seems to rely on a cached size. I created the following sample as a test. When running on Vista it'll report the same size repeatedly. It will change at the beginning then stop changing. However if I open or refresh explorer on that directory, it'll then allow the FileGetSize to see the new size. (can be seen with the gui set up in the background, when I refresh the explorer window the GUI will change). It'll also see the new size if I use another script and call the file size. I'm not very good on Vista. Does anyone know if there is a way around this?

#include <GUIConstantsEx.au3>

$url = 'http://download.microsoft.com/download/6/0/f/60fc5854-3cb8-4892-b6db-bd4f42510f28/dotnetfx35.exe'
$file = @DesktopDir & '\xyz.xyz'
InetGet($url,$file,0,1)


    
    GUICreate("My GUI")  ; will create a dialog box that when displayed is centered
    $label=GUICtrlCreateLabel('',10,10,400,200)
    GUISetState()
    Do
        Sleep(10)
        GUICtrlSetData($label,FileGetSize($file))
        $msg = GUIGetMsg()
    Until $msg = $GUI_EVENT_CLOSE

Share this post


Link to post
Share on other sites
AdmiralAlkex

GileGetSize() work correctly, but as you have discovered it won't work for checking files while they are downloading. You should use @InetGetBytesRead instead.

Share this post


Link to post
Share on other sites
stampy

My problem, that this example doesn't show, is that in my full script I'm using an outside program to control the download and not using Inetget(). I was just using GetFileSize() to know how far along I was. Now I'm just trying to figure out how to solve this on Vista as it's always worked on XP.

Share this post


Link to post
Share on other sites
Intruder

My problem, that this example doesn't show, is that in my full script I'm using an outside program to control the download and not using Inetget(). I was just using GetFileSize() to know how far along I was. Now I'm just trying to figure out how to solve this on Vista as it's always worked on XP.

I ran into the same problem, but I solved it with good old DOS techniques, where the output is not cached by Vista.

Func MyFileGetSize( $file )

; " are used to deal with files and directories containing spaces

; @SW_ HIDE is used to avoid flickering shell windows

; for-command used for quicker access to filesize instead of parsing dir-command, for details see for /?

RunWait( @Comspec & ' /c for %f in ("' & $file & '" ) do echo %~zf>%TEMP%\MyFileGetSize.tmp', '', @SW_HIDE )

Dim $fh = FileOpen( @TempDir & '\MyFileGetSize.tmp', 0 )

Dim $line = FileReadLine( $fh )

FileClose( $fh )

FileDelete( @TempDir & '\MyFileGetSize.tmp' )

Return( $line )

EndFunc

Of course, currently there is no error handling in this function. So if you want it bulletproof, add some checks by yourself.

Cheers

Intruder

Edited by Intruder

Share this post


Link to post
Share on other sites
MegaGamerGuy

i found a fix that might work for ya...

i think the issue has something to do with windows search thingy, ever notice how when you browse a folder and u see the green

progress bar in the address bar of the folder ur in? i remember that if i cancel that my files dont show up. this means that

windows isnt keeping track of the files when a folder is open, but intsead only when you manually update it.

$handel = FileOpen($filename, 1) ; Read Only

FileFlush($handel) ; causes windows to flush it's cache and update the information

FIleClose($handel) ; closes the file

FileGetSize($filename)

thar u go :mellow:

Share this post


Link to post
Share on other sites
MegaGamerGuy

i found a fix that might work for ya...

i think the issue has something to do with windows search thingy, ever notice how when you browse a folder and u see the green

progress bar in the address bar of the folder ur in? i remember that if i cancel that my files dont show up. this means that

windows isnt keeping track of the files when a folder is open, but intsead only when you manually update it.

$handel = FileOpen($filename, 1) ; Read Only

FileFlush($handel) ; causes windows to flush it's cache and update the information

FIleClose($handel) ; closes the file

FileGetSize($filename)

thar u go :mellow:

Well seems I may have found a bug in autoit dealing with FileFlush()

it may not be a good idea to use this to manually update the filesize :) in win7 X86 anyways :S

Share this post


Link to post
Share on other sites
monoscout999

you did`t read the whole thread, a thread of two years old... :mellow:

you are pissing outside the jar, posting this as a bug, without considering what other advanced members have to say :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×