# FileDelete

Deletes the specified file on the server.

Throws an exception if the file doesn't exist.

## Method Signature

```
FileDelete(file=[string])
```

### Arguments

| Argument | Type     | Required | Description         | Default |
| -------- | -------- | -------- | ------------------- | ------- |
| `file`   | `string` | `true`   | The file to delete. |         |

## Examples

### Script Syntax

Obtaining files within an archive folder and then removing them if they are older than one hour.

```java
var existingFiles = directoryList( expandPath( "/archive/" ), false, "query" );
for( file in existingFiles ) {
	if( dateDiff( "h", file.DATELASTMODIFIED, now() ) > 1 ) {
		fileDelete( file.DIRECTORY & "\" & file.NAME );
	}
}

```

Result: All files within the archive directory older than one hour will be deleted.

### Additional Examples

```java
fileDelete( "my/path/to/file.md" );

```

## Related

* [ContractPath](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/io/contractpath)
* [CreateTempDirectory](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/io/createtempdirectory)
* [CreateTempFile](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/io/createtempfile)
* [DirectoryCopy](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/io/directorycopy)
* [DirectoryCreate](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/io/directorycreate)
* [DirectoryDelete](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/io/directorydelete)
* [DirectoryExists](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/io/directoryexists)
* [DirectoryList](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/io/directorylist)
* [DirectoryMove](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/io/directorymove)
* [DirectoryRename](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/io/directoryrename)
* [ExpandPath](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/io/expandpath)
* [FileAppend](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/io/fileappend)
* [FileClose](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/io/fileclose)
* [FileCopy](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/io/filecopy)
* [FileExists](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/io/fileexists)
* [FileGetMimeType](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/io/filegetmimetype)
* [FileInfo](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/io/fileinfo)
* [FileIsEOF](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/io/fileiseof)
* [FileMove](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/io/filemove)
* [FileOpen](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/io/fileopen)
* [FileRead](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/io/fileread)
* [FileReadBinary](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/io/filereadbinary)
* [FileReadLine](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/io/filereadline)
* [FileSeek](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/io/fileseek)
* [FileSetAccessMode](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/io/filesetaccessmode)
* [FileSetAttribute](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/io/filesetattribute)
* [FileSetLastModified](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/io/filesetlastmodified)
* [FileSkipBytes](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/io/fileskipbytes)
* [FileWrite](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/io/filewrite)
* [FileWriteLine](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/io/filewriteline)
* [GetCanonicalPath](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/io/getcanonicalpath)
* [GetDirectoryFromPath](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/io/getdirectoryfrompath)
* [GetFileInfo](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/io/getfileinfo)
* [getTempFile](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/io/gettempfile)
* [PropertyFile](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/io/propertyfile)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/io/filedelete.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
