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

# 檔案格式化器

> ArcScript 中用於處理檔案路徑、名稱、副檔名和檔案系統中繼資料的格式化器。

## 常用檔案格式化器

以下格式化器是最常用的檔案格式化器。每個格式化器都提供了一個範例供參考。

<Note>某些格式化器的可選參數周圍的方括號不是必需的；它們僅用於表示該參數是可選的。</Note>

### fileext()

傳回指定檔案的副檔名。

#### 範例

```xml theme={null}
<arc:set attr="myFile" value="[FilePath]" />
<arc:if exp="[myFile | fileext() | equals('.err')]">
  <arc:throw code="1" desc="Error file detected." />
</arc:if>
```

### fullpath()

傳回指定檔案或資料夾的絕對路徑。

#### 範例

```xml theme={null}
<arc:set attr="myFile.relativepath" value="../test.xml" />
<arc:set attr="myFile.absolutepath" value="[myFile.relativepath | fullpath()]" />
```

## 其它檔案格式化器

下面列出了上一節未包含的不太常用的格式化器。

### directory()

傳回由資料夾路徑指定的目錄名稱。

### direxists(\[ifexist]\[, ifnotexist])

如果指定路徑上的資料夾存在，此格式化器會傳回 *true*（或作為 *ifexist* 傳入的值）；否則傳回 *false*（或作為 *ifnotexist* 傳入的值）。

* **ifexist**：如果目錄存在，則傳回的可選值。
* **ifnotexist**：如果目錄不存在，則傳回的可選值。

### filectime()

傳回指定檔案的建立時間。

### fileexists(\[ifexist]\[, ifnotexist])

如果指定路徑上的檔案存在，此格式化器會傳回 *true*（或作為 *ifexist* 傳入的值）；否則傳回 *false*（或作為 *ifnotexist* 傳入的值）。

* **ifexist**：如果檔案存在，則傳回的可選值。
* **ifnotexist**：如果檔案不存在，則傳回的可選值。

### filemtime()

傳回指定檔案的最後修改時間。

### filename()

傳回指定檔案的檔名。

### filesize()

傳回指定檔案的檔案大小。

### getcwd()

傳回當前工作目錄。傳入此格式化器的屬性會被忽略，因此通常使用預設項 `_` 作為輸入。例如：`[_ | getcwd()]`。

### ischild(path\[, ifchild]\[, ifnotchild])

如果 *path* 參數是屬性值所表示路徑的子路徑，則傳回 *true*（或 *ifchild*）；否則傳回 *false*（或 *ifnotchild*）。

* **path**：要與屬性值所表示的路徑進行比較的路徑。
* **ifchild**：如果參數值是屬性值所表示路徑的子路徑，則傳回的可選值。
* **ifnotchild**：如果參數值不是屬性值所表示路徑的子路徑，則傳回的可選值。

### pathcombine(path)

組合兩個路徑字串。

* **path**：要與屬性值所表示的路徑組合的路徑。

### rootpath()

傳回指定路徑的根目錄。

### tofilename()

將屬性值轉換為有效的檔名。用下劃線 (`_`) 替換無效字元。
