Function Reference


Moves a file or directory, notifying the application of its progress through a callback function

#include <WinAPIFiles.au3>
_WinAPI_MoveFileEx ( $sExistingFile, $sNewFile [, $iFlags = 0 [, $pProgressProc = 0 [, $pData = 0]]] )


$sExistingFile The name of the existing file or directory on the local computer.

If $iFlags specifies $MOVE_FILE_DELAY_UNTIL_REBOOT, the file cannot exist on a remote share because delayed operations are performed before the network is available.
$sNewFile The new name of the file or directory on the local computer.

When moving a file, $sNewFile can be on a different file system or volume.
If $sNewFile is on another drive, you must set the $MOVE_FILE_COPY_ALLOWED flag in $iFlags parameter.

When moving a directory, $sExistingFile and $sNewFile must be on the same drive.

If $iFlags specifies $MOVE_FILE_DELAY_UNTIL_REBOOT and $sNewFile is 0, _WinAPI_MoveFileEx() registers $sExistingFile to be deleted when the system restarts.
If $sExistingFile refers to a directory, the system removes the directory at restart only if the directory is empty.
$iFlags [optional] The move options. This parameter can be one or more of the following values:
$pProgressProc [optional] The address of a callback function that is called each time another portion of the file has been moved.
(See MSDN for more information)
$pData [optional] Pointer to the argument to be passed to the callback function.

Return Value

Success: True.
Failure: False, call _WinAPI_GetLastError() to get extended error information


$MOVE_* , $PROGRESS_* constants require #include <APIFilesConstants.au3>

If the $iFlags parameter specifies $MOVE_FILE_DELAY_UNTIL_REBOOT, _WinAPI_MoveFileEx() fails if it cannot access the registry.
The function stores the locations of the files to be renamed at restart in the following registry value:
    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\PendingFileRenameOperations

See Also

Search MoveFileWithProgress in MSDN Library.


#include <APIFilesConstants.au3>
#include <Misc.au3>
#include <WinAPIError.au3>
#include <WinAPIFiles.au3>

Opt('TrayAutoPause', 0)

Local $hProgressProc = DllCallbackRegister('_ProgressProc', 'bool', 'uint64;uint64;uint64;uint64;dword;dword;handle;handle;ptr')

FileDelete(@TempDir & '\Test*.tmp')

ProgressOn('_WinAPI_MoveFileEx()', 'Bigfile Creation...', '')
Local $sFile = @TempDir & '\Test.tmp'
Local $hFile = FileOpen($sFile, 2)
For $i = 1 To 1000000
    FileWriteLine($hFile, "                                                     ")

ProgressOn('_WinAPI_MoveFileEx()', 'Moving...', '0%')
Sleep(500) ; to show the change as moving on same device just rename

If Not _WinAPI_MoveFileEx($sFile, @TempDir & '\Test1.tmp', $MOVE_FILE_COPY_ALLOWED, DllCallbackGetPtr($hProgressProc)) Then
    _WinAPI_ShowLastError('Error moving ' & $sFile)



FileDelete(@TempDir & '\Test*.tmp')

Func _ProgressProc($iTotalFileSize, $iTotalBytesTransferred, $iStreamSize, $iStreamBytesTransferred, $iStreamNumber, $iCallbackReason, $hSourceFile, $hDestinationFile, $pData)
    #forceref $iStreamSize, $iStreamBytesTransferred, $iStreamNumber, $iCallbackReason, $hSourceFile, $hDestinationFile, $pData

    Local $iPercent = Round($iTotalBytesTransferred / $iTotalFileSize * 100)
    If $iPercent = 100 Then
        ProgressSet($iPercent, '', 'Complete')
        ProgressSet($iPercent, $iPercent & "%")

    If _IsPressed('1B') Then
        Return $PROGRESS_CANCEL
EndFunc   ;==>_ProgressProc