orbs Posted October 23, 2020 Posted October 23, 2020 hello everyone, so i need to get file size using only its handle as given by FileOpen(). i don't have the file name as string, so no go on FileGetSize(). trying _WinAPI_GetFileSizeEx(), i get an invalid handle error. _WinAPI_GetLastErrorMessage() says "The handle is invalid." the handle value as returned by FileOpen() is 1. reproducer: #include <WinAPIFiles.au3> #include <WinAPIError.au3> Global $hFile = FileOpen(@ScriptFullPath) Global $iSize = _WinAPI_GetFileSizeEx($hFile) ConsoleWrite(_WinAPI_GetLastErrorMessage() & @CRLF) ConsoleWrite($hFile & ' : ' & $iSize & @CRLF) FileClose($hFile) any ideas? Signature - my forum contributions: Spoiler UDF: LFN - support for long file names (over 260 characters) InputImpose - impose valid characters in an input control TimeConvert - convert UTC to/from local time and/or reformat the string representation AMF - accept multiple files from Windows Explorer context menu DateDuration - literal description of the difference between given dates Apps: Touch - set the "modified" timestamp of a file to current time Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes SPDiff - Single-Pane Text Diff
Developers Jos Posted October 23, 2020 Developers Posted October 23, 2020 The returned $hFile from FileOpen() is not the real filehandle but rather a sequence number, so won't work with the _WinAPI call. ... but when you do the FIleOpen() is guess you do know the actual filename, so am puzzled about your comment not knowing the filename? Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
pixelsearch Posted October 23, 2020 Posted October 23, 2020 @orbs: I tried it that way : $hFile = FileOpen("autoit-v3.3.15.3.zip") FileSetPos($hFile, 0, $FILE_END) ConsoleWrite(FileGetPos($hFile) & @lf) It displayed 17490098 which is the correct size (as shown in Explorer) Musashi and orbs 1 1 "I think you are searching a bug where there is no bug... don't listen to bad advice."
orbs Posted October 23, 2020 Author Posted October 23, 2020 thank you @pixelsearch, your method works. @Jos, the function i'm writing is inside a UDF, working with FileOpen() that is called by the main script. i cannot tell in advance what usage the main script is going to do with my UDF and i don't want to force the main script to pass the file name as string to my UDF. Signature - my forum contributions: Spoiler UDF: LFN - support for long file names (over 260 characters) InputImpose - impose valid characters in an input control TimeConvert - convert UTC to/from local time and/or reformat the string representation AMF - accept multiple files from Windows Explorer context menu DateDuration - literal description of the difference between given dates Apps: Touch - set the "modified" timestamp of a file to current time Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes SPDiff - Single-Pane Text Diff
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