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).
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
#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
- AutoIt - Check if a file exists
- AutoIt - Copy file
- AutoIt - Delete file
- AutoIt - Rename a file
- AutoIt - Check if a file or folder is Read Only
- AutoIt - Set a file or folder as Read Write
Interesting? Share and Let Others Know.
Post a Comment