> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kasoftware.com/llms.txt
> Use this file to discover all available pages before exploring further.

# fileCopy

> 将文件或目录从一个位置复制到另一个位置，支持递归复制和覆盖控制。

将文件或目录复制到指定的路径。

## 必需的参数

* **source**：要复制的文件（包括文件名）或目录的路径。
* **destination**：文件或目录复制到的文件路径（包括文件名）或目录。

## 可选的参数

* **force**：控制操作是否在目标路径中创建丢失的目录。 允许的值为“true”和“false”。 默认值为“true”。 当需要在目标中镜像源的目录结构时，这通常与 **recurse** 参数结合使用。
* **mask**：用于选择要复制的条目的模式。 默认值为“*”。 （例如，掩码“*.xml”匹配源中的所有 xml 文件。）
* **recurse**：从源递归复制文件和目录。 在这种情况下，假定目标是一个目录。 允许的值为“false”和“true”。 默认为“假”。

## 输出属性

* **file:source**: 源文件或路径的完整路径。
* **file:destination**: 目标文件或路径的完整路径。

## 示例

### 复制单个文件

```xml theme={null}
<!-- Creating the input item with the associated source and destination attributes -->
<arc:set attr="input.source" value="/tmp/foo/helloworld.txt" />
<arc:set attr="input.destination" value="/tmp/bar/helloworld.txt" />

<!-- Calling fileCopy and passing in the input item -->
<arc:call op="fileCopy" in="input" out="result">
  <!-- Optional: Logging information about the copied file to the application log --> 
  <arc:set attr="_log.info" value="The file located at [result.file:source] was copied to [result.file:destination]"/>
</arc:call>
```

### 递归复制目录及其内容

执行此脚本时，`/tmp/foo` 中存在的目录结构将镜像到 `/tmp/bar` 中。 仅 .xml 文件从源复制到目标。

```xml theme={null}
<!-- Creating the input item with the associated source and destination attributes -->
<arc:set attr="input.source" value="/tmp/foo" />
<arc:set attr="input.destination" value="/tmp/bar" />

<!-- Adding the optional mask parameter to only copy files in the directory that have the xml file extension --> 
<arc:set attr="input.mask" value="*.xml" />
<!-- Setting the recurse parameter to true to recursively copy any files and directories inside the source location --> 
<arc:set attr="input.recurse" value="true" />
<!-- Setting the force parameter to true so that the operation creates the necessary directories in the destination -->
<arc:set attr="input.force" value="true"/>  

<!-- Calling fileCopy and passing in the input item -->
<arc:call op="fileCopy" in="input" out="result">
  <!-- Optional: Logging information about the copied file to the application log --> 
  <arc:set attr="_log.info" value="The directory [result.file:source] was copied and placed within the following directory: [result.file:destination]"/>
</arc:call>
```
