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

# File Operations

File operations enable you to perform standard file input/output. You can use these operations to move files across directories, log job results, and much more.

The example below uses the `fileWrite` operation in the post-job event to write a new line to a log file:

```xml theme={null}
<api:info title="After Run" desc="This event is fired after running a job.">
  <input name="JobName"         required="true" desc="The name of the job being executed." />
  <input name="Source"          required="true" desc="The name of source connection." />
  <input name="Destination"     required="true" desc="The name of destination connection." />
  <input name="JobStatus"       required="true" desc="The status of the completed run."/>
  <input name="Query#"          required="true" desc="An array containing each query that was executed." />
  <input name="QueryStatus#"    required="true" desc="An array containing the status of each query that was executed." />
</api:info>

<api:set attr="file.file"  value="C://mylog.log"/> 
<api:set attr="file.data"  value="[null | now()]: The Job [_input.jobname] completed with a status of [_input.jobstatus]"/>
<api:set attr="file.mode"  value="truncate"/>

<api:call op="fileWrite" in="file"/>
```

## Operations

* [Copy a File](#filecopy)
* [Create a File](#filecreate)
* [Delete a File](#filedelete)
* [List all Files](#filelistdir)
* [Create a Directory](#filemakedir)
* [Move a File](#filemove)
* [Read a file](#fileread)
* [Read a Line in File](#filereadline)
* [Write to a File](#filewrite)

### fileCopy

Copies a file or a directory to the path that is specified.

| Required Input Attribute | Description                                |
| :----------------------- | :----------------------------------------- |
| source                   | The name of the file that is to be copied. |
| destination              | The name of the file after it is copied.   |

| Optional Input Attribute | Description                                                                                                                                                                  |
| :----------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| force                    | If force is set to `true`, the operation creates missing directories. The allowed values are `true` and `false`. The default value is `true`.                                |
| mask                     | The pattern that is used to select the entries that are to be copied. The default value is `*`.                                                                              |
| recurse                  | Recursively copy files and directories. In this case, the destination is assumed to be a directory. The allowed values are `false` and `true`. The default value is `false`. |

| Output Attribute | Description                            |
| :--------------- | :------------------------------------- |
| file:source      | The full path of the source file.      |
| file:destination | The full path of the destination file. |

### fileCreate

Creates a text file and, optionally, writes to it.

| Required Input Attribute | Description                                 |
| :----------------------- | :------------------------------------------ |
| file                     | The name of the file that is to be created. |

| Optional Input Attribute | Description                                                                                                                                   |
| :----------------------- | :-------------------------------------------------------------------------------------------------------------------------------------------- |
| force                    | If force is set to `true`, the operation creates missing directories. The allowed values are `true` and `false`. The default value is `true`. |
| data                     | The data that is to be written in the file.                                                                                                   |
| mode                     | The mode of writing. The allowed values are `truncate` and `append`. The default value is `truncate`.                                         |
| encoding                 | The encoding of the file. The default value is `UTF-8`.                                                                                       |

| Output Attribute | Description                                |
| :--------------- | :----------------------------------------- |
| file:file        | The full path of the file that is created. |
| file:cdate       | The creation date of the file.             |

### fileDelete

Deletes a file or a directory.

| Required Input Attribute | Description                                              |
| :----------------------- | :------------------------------------------------------- |
| file                     | The name of the file or directory that is to be deleted. |

| Output Attribute | Description                                        |
| :--------------- | :------------------------------------------------- |
| file:file        | The name of the file or directory that is deleted. |

### fileListDir

Lists the files and the directories in the specified path.

| Required Input Attribute | Description                                                                    |
| :----------------------- | :----------------------------------------------------------------------------- |
| path                     | The path whose directories and files will be listed. The default value is `.`. |

| Optional Input Attribute | Description                                                                                                       |
| :----------------------- | :---------------------------------------------------------------------------------------------------------------- |
| mask                     | The pattern that is used for filtering the result entries. The default value is `*`.                              |
| recurse                  | To list entries recursively. The allowed values are `false` and `true`. The default value is `false`.             |
| fileordir                | To list only files or directories. The allowed values are `all`, `files`, and `dirs`. The default value is `all`. |

| Output Attribute | Description                                                                                   |
| :--------------- | :-------------------------------------------------------------------------------------------- |
| file:fullname    | The full path of the file or directory in the current entry.                                  |
| file:name        | The name of the file or directory in the current entry.                                       |
| file:mtime       | The time at which the file or directory in the current entry is written to.                   |
| file:ctime       | The time at which the file or directory in the current entry is created.                      |
| file:atime       | The time at which the file or directory in the current entry is last read from or written to. |
| file:attributes  | A list of attributes of the file or directory in the current entry.                           |
| file:extension   | The extension of the entry.                                                                   |
| file:size        | The size of the file in bytes.                                                                |
| file:isdir       | Whether the entry is a file or a directory.                                                   |

### fileMakeDir

Creates the directory that is specified by the path.

| Required Input Attribute | Description                                      |
| :----------------------- | :----------------------------------------------- |
| path                     | The path of the directory that is to be created. |

| Optional Input Attribute | Description                                                                                                                                   |
| :----------------------- | :-------------------------------------------------------------------------------------------------------------------------------------------- |
| force                    | If force is set to `true`, the operation creates missing directories. The allowed values are `true` and `false`. The default value is `true`. |

| Output Attribute | Description                         |
| :--------------- | :---------------------------------- |
| file:path        | The directory that is created.      |
| file:cdate       | The creation date of the directory. |

### fileMove

Moves a file or a directory to the path specified.

| Required Input Attribute | Description                             |
| :----------------------- | :-------------------------------------- |
| source                   | The source path that is to be moved.    |
| destination              | The destination that is to be moved to. |

| Optional Input Attribute | Description                                                                                                                                   |
| :----------------------- | :-------------------------------------------------------------------------------------------------------------------------------------------- |
| force                    | If force is set to `true`, the operation creates missing directories. The allowed values are `true` and `false`. The default value is `true`. |

| Output Attribute | Description                            |
| :--------------- | :------------------------------------- |
| file:source      | The full path of the source file.      |
| file:destination | The full path of the destination file. |

### fileRead

Reads a text file and pushes out the data.

| Required Input Attribute | Description                              |
| :----------------------- | :--------------------------------------- |
| file                     | The name of the file that is to be read. |

| Optional Input Attribute | Description                                             |
| :----------------------- | :------------------------------------------------------ |
| encoding                 | The encoding of the file. The default value is `UTF-8`. |

| Output Attribute | Description    |
| :--------------- | :------------- |
| file:data        | The file data. |

### fileReadLine

Reads a text file and pushes out the next line.

| Required Input Attribute | Description                   |
| :----------------------- | :---------------------------- |
| file                     | The name of the file to read. |

| Optional Input Attribute | Description                                                              |
| :----------------------- | :----------------------------------------------------------------------- |
| separator                | The separator of the file. The default value is `the newline character`. |
| encoding                 | The encoding of the file. The default value is `UTF-8`.                  |

| Output Attribute | Description                  |
| :--------------- | :--------------------------- |
| file:line        | The line number of the file. |
| file:data        | The file data.               |

### fileWrite

Writes encoded data to a file.

| Required Input Attribute | Description                                 |
| :----------------------- | :------------------------------------------ |
| file                     | The name of the file that is to be read.    |
| data                     | The data that is to be written in the file. |

| Optional Input Attribute | Description                                                                                                                                   |
| :----------------------- | :-------------------------------------------------------------------------------------------------------------------------------------------- |
| force                    | If force is set to `true`, the operation creates missing directories. The allowed values are `true` and `false`. The default value is `true`. |
| mode                     | The mode of writing. The allowed values are `truncate` and `append`. The default value is `truncate`.                                         |
| encoding                 | The encoding of the file. The default value is `UTF-8`.                                                                                       |

| Output Attribute | Description                                   |
| :--------------- | :-------------------------------------------- |
| file:file        | The full path of the file that is written to. |
| file:cdate       | The modified date of the file.                |
