--- title: "system.file.writeFile" description: "Writes the given data to the file at file path filename." --- # system.file.writeFile > Writes the given data to the file at file path filename. This function is used in **Python Scripting**. ## Description Writes the given data to the file at file path filename. If the file exists, the append argument determines whether or not it is overwritten (the default) or appended to. The data argument can be either a string or an array of bytes (commonly retrieved from a BLOB in a database or read from another file using system.file.readFileAsBytes). :::note This function is scoped for Perspective Sessions, but since all scripts in Perspective run on the Gateway, the file must be located on the Gateway's file system. ::: ## Client Permission Restrictions This scripting function has no [Client Permission](../../../ignition-modules/vision/vision-project-properties/vision-project-properties.md#vision-permissions-properties) restrictions. ## Syntax (charData param) `system.file.writeFile(filepath, charData, [append], [encoding])` ### Parameters Type | Parameter | Description ------- | ------- | ------ String| `filepath` | The path of the file to write to. String| `charData` | The character content to write to the file. Boolean| `append` | If true, the file will be appended to if it already exists. If false, the file will be overwritten if it exists. The default is false. [optional] String| `encoding` | The character encoding of the file to write. Will throw an exception if the string does not represent a supported encoding. Common encodings are "UTF-8", "ISO-8859-1" and "US-ASCII". Default is "UTF-8". [optional] ### Returns Nothing ### Scope Gateway, Vision Client, Perspective Session ## Syntax (data param) `system.file.writeFile(filepath, data, [append], [encoding])` ### Parameters Type | Parameter | Description ------- | ------- | ------ String| `filepath` | The path of the file to write to. Byte[]| `data` | The binary content to write to the file. Boolean| `append` | If true, the file will be appended to if it already exists. If false, the file will be overwritten if it exists. The default is false. [optional] String| `encoding` | The character encoding of the file to write. Will throw an exception if the string does not represent a supported encoding. Common encodings are "UTF-8", "ISO-8859-1" and "US-ASCII". Default is "UTF-8". [optional] ### Returns Nothing ### Scope Gateway, Vision Client, Perspective Session ## Code Examples :::caution The [system.file.saveFile](appendix\scripting-functions\system-file\system-file-saveFile.md) function used in the examples below is only a Vision Client function, so the following scripts will not work in Perspective. ::: ```python title="Example #1" #This code would download a BLOB from a database and save it to a file. resultSet = system.db.runQuery("SELECT file_data FROM Files WHERE id=12") if len(resultSet) > 0: # if the query returned anything... data = resultSet[0][0] # grab the BLOB at the 0th row and 0th column filename = system.file.saveFile("MyDownloadedFile.xyz") if filename is not None: system.file.writeFile(filename, data) ``` ```python title="Example #2" # This code would write the contents of a text area to a file. data = event.source.parent.getComponent("Text Area").text filename = system.file.saveFile("MyDownloadedFile.txt") if filename is not None: system.file.writeFile(filename, data) ```