$cs.File_CopyFile
Description
Section titled “Description”Copies source to destination. If destination is an existing folder, or ends with a path separator (\), the source’s filename is automatically appended to it, so you can pass just a target folder. The destination’s parent folder is created automatically if it doesn’t exist.
If the copy itself fails — for example, because the destination file is locked or access is denied — the function doesn’t raise an error. The failure is only written to the debug log, CapaOne.ScriptingLibrary.log, in the same folder as the package log. To be sure the file arrived, check it afterwards with $cs.File_ExistFile or $cs.File_GetFileVersion.
Syntax
Section titled “Syntax”$cs.File_CopyFile(string source, string destination, bool overwrite = true)
Parameters
Section titled “Parameters”source (String)
Section titled “source (String)”Full path to the file to copy. Throws an error if it does not exist.
destination (String)
Section titled “destination (String)”Full path (or folder) to copy the file to.
overwrite (Boolean)
Section titled “overwrite (Boolean)”Overwrite the destination if it already exists. Default is $true. If set to $false and the destination file already exists, the copy is silently skipped — no error is raised.
Return value
Section titled “Return value”None.
Example
Section titled “Example”$cs.File_CopyFile("C:\Program Files\CapaInstaller\dummy.exe","C:\Windows\dummy2.exe")This copies a log file to the PowerPack’s log folder, making it visible in the CapaInstaller Console:
$Destination = Join-Path $global:AppLogFolder "dism.log"$cs.File_CopyFile("C:\Windows\Logs\DISM\dism.log", $Destination)Passing a folder (or a path ending in \) as the destination copies the file into it under its original filename:
$Source = Join-Path $global:Packageroot "kit\license.lic"$cs.File_CopyFile($Source, "C:\Program Files\Contoso\App\")When deploying a default configuration file, use overwrite=$false so an end user’s existing customized copy is left untouched:
$Source = Join-Path $global:Packageroot "kit\default.ini"$cs.File_CopyFile($Source, "C:\ProgramData\Contoso\App\settings.ini", $false)