Jump to content
orbs

get file size using handle

Recommended Posts

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?

 

Share this post


Link to post
Share on other sites

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.
  :)

Share this post


Link to post
Share on other sites

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.

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

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...