如何在AutoIt中找到复制失败的原因?

时间:2016-08-12 08:14:58

标签: autoit

AutoIt FileCopy method定义了以下返回值:

  

返回值

     

成功:1   失败:0。

显然,当文件复制操作失败时,我想告诉用户为什么失败。我如何获得这些信息?

1 个答案:

答案 0 :(得分:2)

编辑:带有消息输出的重写函数(最后一个错误不适用于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