LATEST UPDATES
ShareHolder Finder v0.9.3 is now released!!! Check Product Page for more details.
✉ info@automationdevelopers.com

ITS ALL ABOUT AUTOMATION

Saturday, 16 April 2016

AutoIt - Move file


Author Post Date Saturday, 16 April 2016
To move one or more files, the function FileMove ( "source", "dest" [, flag = 0] ) is used.

source - The source path and filename of the file to move. (* wildcards accepted - See Remarks)
dest - The destination path and filename of the moved file. (* wildcards accepted - See Remarks)
flag [optional] - This flag determines whether to overwrite files if they already exist.
Can be a combination of the following:
              $FC_NOOVERWRITE (0) = (default) do not overwrite existing files.
              $FC_OVERWRITE (1) = overwrite existing files.
              $FC_CREATEPATH (8) = Create destination directory structure if it doesn't exist (See Remarks).
Constants are defined in FileConstants.au3.

The destination directory must already exist, except using with flag value $FC_CREATEPATH (8).

The function returns 1 for success and 0 for failure.

Example:

#include <MsgBoxConstants.au3>
#include <FileConstants.au3>

;Assign the source file path to a variable.
Local $sSourceFilePath = @ScriptDir & "\temp.txt"

;Assign the destination directory to a variable.
Local $sDestPath = "C:\AutomationDevelopers\"

;Create temp.txt to move.
If Not FileWrite($sSourceFilePath, "This is an example of using FileMove.") Then
    MsgBox($MB_SYSTEMMODAL, "", "An error occurred while writing the file.")
EndIf

;Execute the move function.
Local $iMoveStatus = FileMove($sSourceFilePath, $sDestPath, $FC_OVERWRITE + $FC_CREATEPATH)

;Display the status after checking the returned value.
If $iMoveStatus Then
    MsgBox($MB_SYSTEMMODAL, "", "Move Success")
Else
    MsgBox($MB_SYSTEMMODAL, "", "Move Failed")
EndIf

Related Posts




Interesting? Share and Let Others Know.

Post a Comment