Sign in to follow this  
Followers 0
madasraka

inetgetfilesize

4 posts in this topic

#1 ·  Posted (edited)

If help file says

Not all servers will correctly give the file size, especially when using a proxy server.

then

how do i get percentage of file downloaded if i try to match remote file size and local file size ?

Is there another way to calculate % of file being downloaded without knowing its size ?

Thanks in advance

Here is my code

$URL = GUICtrlRead ($Address)
        $Destination = (GUICtrlRead ($OutputDir)) & ($Folder)
        DirCreate ($Destination)
        $Percent = "0"
        $Download = InetGet ($FileURL,$Destination & "\" & $RenamedFile,1,1) ;download file from $url set by each selected book
        $FileSizeRemote = (InetGetSize ($FileURL,1) / 1024);size of file (that is downloading)
        Do
            $FileSizeLoop = (FileGetSize ($Destination & "\" & $RenamedFile) / 1024);size of file (that is downloading)
            GUICtrlSetData ($Completed,$FileSizeRemote & " out of " & $FileSizeLoop & " so far.")
            $Msg = GUIGetMsg() ;this is to read the button to make sure you can stop it in the middle of the process
            Switch $Msg
                Case $Start
                    If InetGetInfo ($Download,4) = @error Then $Ask = MsgBox(1+32,'Information',$RenamedFile &' was not completed.' & @CRLF & 'Currently downloading file will be erased.'& @CRLF &'Are you sure you want to stop ?')
                    If $Ask = 1 Then
                        InetClose ($Download)
                        FileDelete ($Destination & "\" & $RenamedFile)
                        ;Exit
                        GUICtrlSetData ($Progress,"0")
                        Guictrlsetdata ($Start,"Start")
                        Return
                    Else
                        ;nothing
                    EndIf
                EndSwitch
            GUICtrlSetData ($Status,"Downloading." & @CRLF & "Please wait.")
        Until InetGetInfo ($Download,2)

I also noticed:

Filegetsize returns filesize only when i right click and refresh in explorer :x rather then refreshing it on its own. Almost as if autoit does not get file size unless you see it in explorer

Windows 7 64bit

Edited by madasraka

Share this post


Link to post
Share on other sites



how do i get percentage of file downloaded if i try to match remote file size and local file size ?

$iPerc = round($iLocalFileSize / $iFinalFileSize * 100)

Is there another way to calculate % of file being downloaded without knowing its size ?

Not unless your name is Harry Potter. :x

So ... if you can't trust the returned online filesize. (I'm assuming it can be anything as I never checked that part.)

- use some (true/false) flag that tells your code to display, or not to display, a progress bar. (start with true)

- when percentage is 100 or above and download is not yet complete, set this flag to false. (filesize was incorrect)

Filegetsize returns filesize only when ... refresh

Mmm, not sure. But you could try if you can force a refresh from within AutoIt with a FileOpen()+FileClose() on the local file. (ReadOnly). And toss in a FileFlush() if that did not work.

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Share this post


Link to post
Share on other sites

$iPerc = round($iLocalFileSize / $iFinalFileSize * 100)

Help file said some websites return incorrect file size. That must be because file is compressed on server side, so its like reading not "file size" but "file size on disk" which is different due to compression of NTFS or any other partition server might have.

InetGetSize needs some more options to make the server return the actual file size and not what HTTP or FTP server thik (But that must be the hosting application issue, not the autoit function)

Mmm, not sure. But you could try if you can force a refresh from within AutoIt with a FileOpen()+FileClose() on the local file. (ReadOnly). And toss in a FileFlush() if that did not work.

$OpenFile = FileOpen ($Destination & "\" & $RenamedFile)
            GUICtrlSetData ($Completed,"Downloading " & $RenamedFile & @CRLF & (FileGetSize ($Destination & "\" & $RenamedFile) / 1024) & " KB")
            FileClose ($OpenFile)
            FileFlush ($OpenFile)

Not working. It will only show size which OS noticed few ms's later after file creation.

Its like return value depends on what OS says rather then calculating it.

Autoit would display current and correct size after only if i click on that file nr refresh folder in which file is locater thus refreshing OS information rather then autoit functio.

That is why i never use any dll dependent codes on my scrits, caz those cant be trusted.

Filegetsize function need work (period) or maybe a tweak i "dont know" :x

Thanks for trying to help.

Do you know of any other way to make OS to refresh file information so that filegetsize reads it ?

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Not working. It will only show size which OS noticed few ms's later after file creation.

Ok, not tested myself, but I'll take your word for it.

Little bit more brainstorming ...

The next best thing that comes to mind is to look for some WinAPI call that forces window to update its information on the/a target file. Taking a quick look at WinAPI UDF ... WinAPI_ShellGetFileInfo() might help.

(also toggling the archive attribute on a file might be a idea. With AutoIt internal function or with a WinAPI call.)

Edited by MvGulik

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

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  
Followers 0