Copies one or more files.
FileCopy ( "source", "dest" [, flag = 0] )
source | The source path of the file(s) to copy. (* and ? wildcards accepted - See Remarks) |
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. |
Success: | 1. |
Failure: | 0. |
See FileFindFirstFile() for a discussion about wildcards.
The destination directory must already exist, except using with flag value $FC_CREATEPATH (8).
For instance the combined flag $FC_OVERWRITE (1) + $FC_CREATEPATH (8) overwrites the target file and pre-checks for the destination directory structure and if it doesn't exist creates it automatically.
Some file attributes can make the overwriting impossible, if this is the case look at FileSetAttrib() to change the attributes of a file.
DirCopy, DirCreate, FileDelete, FileMove
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>
Example()
Func Example()
; Create a constant variable in Local scope of the filepath that will be read/written to.
Local Const $sFilePath = _WinAPI_GetTempFileName(@TempDir)
; Create a temporary file to copy.
If Not FileWrite($sFilePath, "This is an example of using FileCopy.") Then
MsgBox($MB_SYSTEMMODAL, "", "An error occurred whilst writing the temporary file.")
Return False
EndIf
; Copy Au3 files in the temporary directory to a new folder/directory called Au3Files.
FileCopy(@TempDir & "\*.au3", @TempDir & "\Au3Files\", $FC_OVERWRITE + $FC_CREATEPATH)
; Display the temporary directory.
ShellExecute(@TempDir)
EndFunc ;==>Example