4

The AutoIt FileCopy method defines the following return values:

Return Value

Success: 1.
Failure: 0.

Obviously, when the file copy operation fails, I'd like to tell the user why it fails. How do I get that information?

Heinzi
  • 167,459
  • 57
  • 363
  • 519

1 Answers1

2

Edit : rewrited function with message output (last error doesn t work with au3 filecopy)

ConsoleWrite(copyFile("./ft", "./tg8"))


Func copyFile($source, $dest)

    $ret = DllCall("kernel32.dll", "int", _
            "CopyFileEx", _ ; W
            "str", $source, _
            "str", $dest, _
            "ptr", Null, _ ;no callback
            "str", Null, _
            "int", 0, _
            "int", 0)

    Return _GetLastErrorFormatMessage()

EndFunc   ;==>copyFile



Func _GetLastErrorFormatMessage()
    Local Const $FORMAT_MESSAGE_FROM_SYSTEM = 0x00001000
    Local $ret = ""
    Local $message = ""
    Local $err = ""
    Local $buff = DllStructCreate("char[4096]")

    $err = DllCall("Kernel32.dll", "int", "GetLastError")
    $ret = DllCall("kernel32.dll", "int", "FormatMessage", _
            "int", $FORMAT_MESSAGE_FROM_SYSTEM, _
            "ptr", 0, _
            "int", $err[0], _
            "int", 0, _
            "ptr", DllStructGetPtr($buff), _
            "int", 4096, _
            "ptr", 0)
    $message = DllStructGetData($buff, 1)
    $buff = Null
    Return $message
EndFunc   ;==>_GetLastErrorFormatMessage