Jump to content

Determining location from file handle


Recommended Posts

Hola!

I've a quick question (hopefully) that I was unable to find an answer for in the forums or in the help. I am logging messages to a file which was created with FileOpen, so I have a handle to the file in a variable. I've a situation where I want to do a screen capture and save it in the same location as I have the log file. Is it possible to determine the location of the log file on my drive from sending it's handle to a function (either one packaged in Autoit or a UDF)? Or am I stuck with having to pass my function a variable containing the location in addition to the file handle (thus causing a lot of code changes to include the new parameter)? Apologies if it is an obvious answer, but my search in both areas did not produce.

Thanks in advance...

Link to comment
Share on other sites

Welcome to the Autoit Forum bytorsnowdog,

What if you had a variable with your log file path and then run a function after the screen capture to save it to the same location as the log file.

jfcby

Determined -- Devoted -- Delivered Make your mind up -- to seriously apply yourself -- accomplishing the desired results. **** A soft answer turneth away wrath: but grievous words stir up anger. Proverbs 15:1 KJB ****

Link to comment
Share on other sites

Thank you for both the welcome and the reply, jfcby!

Yes, I already have the variable with the string of the log file location outside of my UDF, but was hoping to avoid having to add another parameter to the function by some means to determine location via the file handle. But, I'm gauging from the lack of responses to my post that there probably isn't a way to do that. I've also thought about just creating a new UDF with the additional parameter to avoid having to go back and change code in multiple scripts that call the original function.

Again, thank you!

Link to comment
Share on other sites

I'm sorry - read your suggestion just a bit wrong. Yes, I could have a separate function called by the script to do the screen capture. But, again, I was hoping that there would be an elegant way to find out the location from the file handle.

Again, Thanks!

Link to comment
Share on other sites

Native AutoIt file handles don't have this to my knowledge, but the Windows API has "GetFinalPathNameByHandle" which is probably in the WinAPI.au3 library...

err...humm, I guess it's not...

Well, here's the wrapper and example:

#include <WinAPI.au3>
$sFile = @ScriptDir & "\test.html"
$hFile = _WinAPI_CreateFile($sFile, 2)

$path = _WinAPI_GetFinalPathNameByHandle($hFile)
MsgBox(0,"",$path)


Func _WinAPI_GetFinalPathNameByHandle($hFile)
    Local $aResult = DllCall("kernel32.dll", "DWORD", "GetFinalPathNameByHandle", "handle", $hFile, "str", 0,"DWORD",260,"DWORD",0)
    If @error Then Return SetError(@error, @extended, 0)
    Return $aResult[2]
EndFunc   ;==>_WinAPI_GetFinalPathNameByHandle

Might be a valid feature request if you care to submit it.

Link to comment
Share on other sites

not sure if an new UDF is needed But at least you can use Glbal varibale if you dont want to modify your function.

Doh! I should have thought of that earlier. Guess I'm trying to approach it from too much of a purest POV!

Thanks to all for the replies!

btsd

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...