To copy one or more files, the function FileCopy ( "source", "dest" [, flag = 0] ) is used.
source - The source path of the file(s) to copy. (* and ? wildcards accepted)
dest - The destination path of the copied file(s).
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.
source - The source path of the file(s) to copy. (* and ? wildcards accepted)
dest - The destination path of the copied file(s).
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 copy.
If Not FileWrite($sSourceFilePath, "This is an example of using FileCopy.") Then
MsgBox($MB_SYSTEMMODAL, "", "An error occurred while writing the file.")
EndIf
;Execute the copy function.
Local $iCopyStatus = FileCopy($sSourceFilePath, $sDestPath, $FC_OVERWRITE + $FC_CREATEPATH)
;Display the status after checking the returned value.
If $iCopyStatus Then
MsgBox($MB_SYSTEMMODAL, "", "Copy Success")
Else
MsgBox($MB_SYSTEMMODAL, "", "Copy 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 copy.
If Not FileWrite($sSourceFilePath, "This is an example of using FileCopy.") Then
MsgBox($MB_SYSTEMMODAL, "", "An error occurred while writing the file.")
EndIf
;Execute the copy function.
Local $iCopyStatus = FileCopy($sSourceFilePath, $sDestPath, $FC_OVERWRITE + $FC_CREATEPATH)
;Display the status after checking the returned value.
If $iCopyStatus Then
MsgBox($MB_SYSTEMMODAL, "", "Copy Success")
Else
MsgBox($MB_SYSTEMMODAL, "", "Copy Failed")
EndIf
- AutoIt - Check if a file exists
- AutoIt - Move 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.
nice
ReplyDelete