CygnusX1 Posted November 20, 2014 Share Posted November 20, 2014 Hi, I'm totally stumped on how to get a file size. I have read the help on FileGetSize(), the example doesn't work. I read I needed to use _WinAPI because FileGetSize() doesn't work on a search handle. I tried using the WinAPI but I can't seem to get that to work either. I have looked all over help and done Google searches. I'm sure it is something easy but I'm overlooking it. The file search works, at least I'm getting the file names and VarGetType reveals it is a string. _WinAPI_GetFileSize show it is an Int64. I'm close.... Local $search = FileFindFirstFile(file_path & "*.*") While 1 Local $file = FileFindNextFile($search) If @error Then ExitLoop $new_file = _WinAPI_CreateFile($file, 2) $size = _WinAPI_GetFileSizeEx($new_file) ConsoleWrite("File: " & $file & " Size: " & $size & @LF) WEnd ; Close the search handle _WinAPI_CloseHandle($file) Thank you. Brad Cygnus Link to comment Share on other sites More sharing options...
water Posted November 20, 2014 Share Posted November 20, 2014 This example works. I only added a check to drop directories. #include <MsgBoxConstants.au3> Local $hSearch = FileFindFirstFile("*.*") ; Check if the search was successful, if not display a message and return False. If $hSearch = -1 Then MsgBox($MB_SYSTEMMODAL, "", "Error: No files/directories matched the search pattern.") Exit EndIf Local $sFileName = "", $iResult = 0 While 1 $sFileName = FileFindNextFile($hSearch) ; If there is no more file matching the search. If @error Then ExitLoop ; if it is a file then get the filesize If @extended <> 1 Then $iResult = MsgBox(BitOR($MB_SYSTEMMODAL, $MB_OKCANCEL), "", "File: " & $sFileName & @CRLF & "FileSize: " & FileGetSize($sFileName)) If $iResult <> $IDOK Then ExitLoop ; If the user clicks on the cancel/close button. Endif WEnd ; Close the search handle. FileClose($hSearch) My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
CygnusX1 Posted November 20, 2014 Author Share Posted November 20, 2014 Hey, Thanks for the quick reply. I changed the code just a bit to make it more simple to display my issue. If I run the code on my C:WindowsSystem32 look at work I get. Local $hSearch = FileFindFirstFile("C:\Windows\System32\*.*") ; Check if the search was successful, if not display a message and return False. If $hSearch = -1 Then MsgBox($MB_SYSTEMMODAL, "", "Error: No files/directories matched the search pattern.") Exit EndIf Local $sFileName = "", $iResult = 0 While 1 $sFileName = FileFindNextFile($hSearch) ; If there is no more file matching the search. If @error Then ExitLoop ConsoleWrite("File: " & $sFileName & ", " & "Size: " & FileGetSize($sFileName) & @LF) WEnd ; Close the search handle. FileClose($hSearch) File: 0409, Size: 0 File: 12520437.cpx, Size: 0 File: 12520850.cpx, Size: 0 File: aaclient.dll, Size: 0 File: accessibilitycpl.dll, Size: 0 File: ACCTRES.dll, Size: 0 File: acledit.dll, Size: 0 File: aclui.dll, Size: 0 File: acppage.dll, Size: 0 File: ActionCenter.dll, Size: 0 File: ActionCenterCPL.dll, Size: 0 File: activeds.dll, Size: 0 File: activeds.tlb, Size: 0 File: actxprxy.dll, Size: 0 ... ... ... ... etc.... What is going on? I have the latest Version of AutoIt. Cygnus Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 20, 2014 Moderators Share Posted November 20, 2014 CygnusX1, I have read the help on FileGetSize(), the example doesn't workSo when you run the example in the Help file inside SciTE it does not produce a MsgBox showing a value of about 900 Kb? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
CygnusX1 Posted November 20, 2014 Author Share Posted November 20, 2014 I stand corrected the example did work. What is my code doing that is different? Thank you. Brad Cygnus Link to comment Share on other sites More sharing options...
BrewManNH Posted November 20, 2014 Share Posted November 20, 2014 You need the file's PATH and File name, not just the file's name. #include<msgboxconstants.au3> Global $sFilePath = "C:\Windows\System32\" Local $hSearch = FileFindFirstFile($sFilePath & "*.*") ; Check if the search was successful, if not display a message and return False. If $hSearch = -1 Then MsgBox($MB_SYSTEMMODAL, "", "Error: No files/directories matched the search pattern.") Exit EndIf Local $sFileName = "", $iResult = 0 While 1 $sFileName = FileFindNextFile($hSearch) ; If there is no more file matching the search. If @error Then ExitLoop ConsoleWrite("File: " & $sFilePath & $sFileName & ", " & "Size: " & FileGetSize($sFilePath & $sFileName) & @LF) WEnd ; Close the search handle. FileClose($hSearch) If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
CygnusX1 Posted November 20, 2014 Author Share Posted November 20, 2014 My Fellow NH-ite! Thank you! That did it. It might be good if the help was updated to include some verbiage around this. I guess this post can be marked as answered. Thanks BrewManNH, "Live Free or Die" Cygnus Link to comment Share on other sites More sharing options...
BrewManNH Posted November 20, 2014 Share Posted November 20, 2014 My Fellow NH-ite! Thank you! That did it. It might be good if the help was updated to include some verbiage around this. I hadn't noticed that the help file doesn't specify that the path would be needed as well, but it wouldn't hurt to add it. Thanks BrewManNH, "Live Free or Die" If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 20, 2014 Moderators Share Posted November 20, 2014 CygnusX1, It might be good if the help was updated to include some verbiage around thisIn the Help file under <Using AutoIt - File Name and Path> you will find: Whenever a function parameter is specified as "filename", it implies a filename with a full pathThe syntax for FileGetSize says: FileGetSize ( "filename" )I think that is clear enough. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
CygnusX1 Posted November 20, 2014 Author Share Posted November 20, 2014 RTFM on my part Cygnus Link to comment Share on other sites More sharing options...
jdelaney Posted November 20, 2014 Share Posted November 20, 2014 You can use just the name, if your context is right. FileChangeDir ( "path" ) IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
BrewManNH Posted November 20, 2014 Share Posted November 20, 2014 CygnusX1, In the Help file under <Using AutoIt - File Name and Path> you will find: Whenever a function parameter is specified as "filename", it implies a filename with a full path The syntax for FileGetSize says: FileGetSize ( "filename" ) I think that is clear enough. M23 I would disagree that it's all that clear, in that I think it shouldn't just be mentioned in some obscure part of the help file. that information should be linked to the word "filename" in every function that uses it in the help file. We have links to practically everything else in there now, this should definitely be there as well. I've used AutoIt for over 4 years, and I've never read that section of the help file, it might be a new addition which is why I haven't read it before. Maybe I'll take a look at that this week and see what's practical. CygnusX1 1 If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 20, 2014 Moderators Share Posted November 20, 2014 BrewManNH, that information should be linked to the word "filename" in every function that uses it in the help fileOver to you then! Seriously, we added that page some time ago and made sure that function syntax used the correct terminology - before that there was a real mixture of terms: "file", "filename", "filepath", "file name and path", etc. I do not believe we need to do more - this is not a common problem as most people realise that both a name and a path are needed to identify a specific file. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
BrewManNH Posted November 20, 2014 Share Posted November 20, 2014 (edited) It can't hurt to make it clearer. Like I said, we have links to things in the help file now that were only recently linked in the remarks sections of functions, so linking to a page that tells you what "filename" means in the help file would be helpful. EDIT: I will be taking a look at the help file txt files to see where "filename" is used and figuring out the link needed. Edited November 20, 2014 by BrewManNH If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator 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