> ## 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>
```
