TheSaint Posted November 8, 2016 Share Posted November 8, 2016 (edited) See Post #13 for the solution. Not had any luck on this yet, but still trying ... testing any method that suggests itself. THE SCENARIO I have a third party program downloading a file, and it doesn't display size as the file grows ... or even show what the final size may be. So I am attempting to at least report on the growing file size. However, a well known issue with Windows Explorer, is that it doesn't continually refresh, so something needs to occur to make it do so. In an open folder window, one can press F5 or send it via code. Or one can select another file. The true file size then shows. THE QUESTION Is their some way, programmatically, with the destination folder window closed, where you can force Explorer to refresh itself for the content of that folder and thus get the file size at the time of querying? Note, I am using the FileGetSize command of course. P.S. I attempted a Win API variant, but failed ... probably did it wrong. Perhaps VBScript has something, but I'd rather I just used some method via AutoIt ... but any solution will do in a pinch. MY CODE If FileExists($vidfle) Then ;_FileCreate($tmpfle) ;$size = FileGetSize($tmpfle) ; ;$handle = _WinAPI_CreateFile($vidfle, 2, 2) ;$size = _WinAPI_GetFileSizeEx($handle) ;_WinAPI_CloseHandle($handle) ; $size = FileGetSize($vidfle) If $size <> 0 Then $size = $size / 1048576 If $size > 999 Then $size = Round($size / 1024, 2) & " Gb" Else $size = Round($size) & " Mb" EndIf GUICtrlSetData($Label_sze, $size) EndIf EndIf Edited November 9, 2016 by TheSaint Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage) Link to comment Share on other sites More sharing options...
j0kky Posted November 9, 2016 Share Posted November 9, 2016 Have you tried to FileFlush before getting the size? Spoiler Some UDFs I created: Winsock UDF STUN UDF WinApi_GetAdaptersAddresses _WinApi_GetLogicalProcessorInformation Bitwise with 64 bit integers An useful collection of zipping file UDFs Link to comment Share on other sites More sharing options...
Jfish Posted November 9, 2016 Share Posted November 9, 2016 Another thought, could you use a command line function with StdoutRead and bypass any refreshing of explorer? Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt Link to comment Share on other sites More sharing options...
TheSaint Posted November 9, 2016 Author Share Posted November 9, 2016 23 minutes ago, j0kky said: Have you tried to FileFlush before getting the size? FileFlush. Up until now, I never heard of that command. Doesn't sound suitable either, as it requires FileOpen ... plus it doesn't exist in v3.3.0.0. of AutoIt, which I am using ... and I am not about to update a whole script for it in any case, unless it is known definitely to work ... and no other solution exists. 25 minutes ago, Jfish said: Another thought, could you use a command line function with StdoutRead and bypass any refreshing of explorer? How? What? Where? No idea springs to mind. Thanks guys, but they sound like experiments and not something that is known to work, and I was hoping for something from someone who has already solved this very common issue ... it can happen with both file move & copy too. Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage) Link to comment Share on other sites More sharing options...
Jfish Posted November 9, 2016 Share Posted November 9, 2016 (edited) 22 minutes ago, TheSaint said: How? What? Where? No idea springs to mind. I tested this which I got from Stackoverflow to get the file size: forfiles /p C:\Temp /m file1.txt /c "cmd /c echo @fsize" replace c:\temp with your path and file1,txt with your file and it will echo the filesize. Edited November 9, 2016 by Jfish TheSaint 1 Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt Link to comment Share on other sites More sharing options...
TheSaint Posted November 9, 2016 Author Share Posted November 9, 2016 @Jfish - Thanks for that, will give it a try. I have used forfiles before, but had forgotten about it. Just for those wanting a little Valik nostalgia trip, of him in full flight ... and for those who never had the pleasure, but heard the rumors. Gonna see if I can use the code from there as well. SkysLastChance and Xandy 1 1 Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage) Link to comment Share on other sites More sharing options...
Jfish Posted November 9, 2016 Share Posted November 9, 2016 @TheSaint funny thread. One of my favorite passages: Quote After seeing this line of code... please kill yourself. Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt Link to comment Share on other sites More sharing options...
TheSaint Posted November 9, 2016 Author Share Posted November 9, 2016 A funny one indeed, of classic proportions. It was certainly never dull for long with him around. Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage) Link to comment Share on other sites More sharing options...
j0kky Posted November 9, 2016 Share Posted November 9, 2016 (edited) 8 hours ago, TheSaint said: FileFlush. Up until now, I never heard of that command. Doesn't sound suitable either, as it requires FileOpen ... plus it doesn't exist in v3.3.0.0. of AutoIt, which I am using ... and I am not about to update a whole script for it in any case, unless it is known definitely to work ... and no other solution exists. Yep, Fileflush is supported from the next version of AutoIt, 3.3.2.0. Anyhow, if you don't try other solutions, this script does exatly what you want: Local $hHandle = FileOpen("C:\a.txt"), $tTimer = TimerInit() Do ConsoleWrite(FileGetSize("C:\a.txt") & @CRLF) Sleep(1000) FileFlush($hHandle) Until TimerDiff($tTimer) > 20000 FileClose($hHandle) Edited November 9, 2016 by j0kky TheSaint 1 Spoiler Some UDFs I created: Winsock UDF STUN UDF WinApi_GetAdaptersAddresses _WinApi_GetLogicalProcessorInformation Bitwise with 64 bit integers An useful collection of zipping file UDFs Link to comment Share on other sites More sharing options...
TheSaint Posted November 9, 2016 Author Share Posted November 9, 2016 @j0kky - Thanks, will keep it in mind. May even write a little exe to use it with my older script. Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage) Link to comment Share on other sites More sharing options...
j0kky Posted November 9, 2016 Share Posted November 9, 2016 (edited) 51 minutes ago, TheSaint said: @j0kky - Thanks, will keep it in mind. May even write a little exe to use it with my older script. On second thoughts, to be compatible with your version, FileFlush can be easily replaced with FlushFileBuffers API: Local $hHandle = FileOpen("C:\a.txt"), $tTimer = TimerInit() Do ConsoleWrite(FileGetSize("C:\a.txt") & @CRLF) Sleep(1000) DllCall("Kernel32.dll", "BOOLEAN", "FlushFileBuffers", "HANDLE", $hHandle) Until TimerDiff($tTimer) > 20000 FileClose($hHandle) Edited November 9, 2016 by j0kky TheSaint 1 Spoiler Some UDFs I created: Winsock UDF STUN UDF WinApi_GetAdaptersAddresses _WinApi_GetLogicalProcessorInformation Bitwise with 64 bit integers An useful collection of zipping file UDFs Link to comment Share on other sites More sharing options...
TheSaint Posted November 9, 2016 Author Share Posted November 9, 2016 Once again thanks. Will try that shortly. Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage) Link to comment Share on other sites More sharing options...
TheSaint Posted November 9, 2016 Author Share Posted November 9, 2016 (edited) @j0kky - once more I thank you. My first little test run worked beautifully. And on repeated use. Local $handle If FileExists($vidfle) Then $handle = FileOpen($vidfle, 0) ;$size = FileGetSize($vidfle) DllCall("Kernel32.dll", "BOOLEAN", "FlushFileBuffers", "HANDLE", $handle) $size = FileGetSize($vidfle) ;DllCall("Kernel32.dll", "BOOLEAN", "FlushFileBuffers", "HANDLE", $handle) ;$size = FileGetSize($vidfle) FileClose($handle) ; If $size <> 0 Then $size = $size / 1048576 If $size > 999 Then $size = Round($size / 1024, 2) & " Gb" Else $size = Round($size) & " Mb" EndIf GUICtrlSetData($Label_sze, $size) EndIf EndIf Because of timing constraints, I could not use the Call in a loop or with any significant delay (part of a STD_READ loop writing to my own version of a Console). I will now fine tune to see what I can get away with. It's all a bit convoluted, because I code on my WinXP machine, then test and use on my Win 7 Netbook, and the Win XP Laptop just decided to freeze on me during a SciTE save ... it does that once in a while ... getting a bit old in the tooth. So here I am while it takes its sweet time restarting. EDIT Was able to do away with second DLL call and first FileGetSize. Edited November 9, 2016 by TheSaint Tony4219 1 Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage) Link to comment Share on other sites More sharing options...
TheSaint Posted November 10, 2016 Author Share Posted November 10, 2016 JFYI - Here's a screenshot of my Console in action, where the 80 Mb is the growing size, being reported using the code from the previous post. NOTE - The 541 Mb total, is just an estimation based on averaging the size of the first five fragments of the download, times total number of fragments. Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage) Link to comment Share on other sites More sharing options...
Tony4219 Posted January 13, 2023 Share Posted January 13, 2023 Thanks to TheSaint and Jokky !!! For the last 2-3 days I have been running around in coding circles. I too, wanted to monitor download progress by checking file size repeatedly. I too, noticed that WinExplorer does not refresh itself, so that didn't work. What I did notice was that if I manually checked the file's Properties, I could see the correct, current size. But even then, WinExplorer did not refresh itself even tho I had righclicked the actual file inside the WinExplorer window! Wasted LOTS of time trying to find a way to make WinExplorer refresh itself and trying to check file Properties. Luckily I found this 7 year old discussion of FileBuffers needing refreshing. But you need Handle to the actual file to do that. Again, thanks for showing me how to do both. Tony4219 TheSaint 1 Link to comment Share on other sites More sharing options...
Nine Posted January 14, 2023 Share Posted January 14, 2023 Sorry to break the fun here, but the API FlushFileBuffers cannot use AutoIt file handle. It requires Windows file handle. So the statement is useless and erroneous... “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
rudi Posted January 19, 2023 Share Posted January 19, 2023 This thread is from 2016 ... Earth is flat, pigs can fly, and Nuclear Power is SAFE! Link to comment Share on other sites More sharing options...
Nine Posted January 19, 2023 Share Posted January 19, 2023 I know, but it is still wrong, whatever date creation it was...I think it is important to tell searchers like Tony. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
rudi Posted January 20, 2023 Share Posted January 20, 2023 @Nine that's right, iirc usually you (also) pointed out "This is an old (dead) thread, pls do not jump in to very old threads, open a new one" ? Earth is flat, pigs can fly, and Nuclear Power is SAFE! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now