> For the complete documentation index, see [llms.txt](https://boxlang.ortusbooks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/io/directorydelete.md). Agents can also search and read this documentation through its [MCP server](https://boxlang.ortusbooks.com/~gitbook/mcp).

# DirectoryDelete

Deletes a directory

## Method Signature

```
DirectoryDelete(path=[string], recursive=[boolean], followLinks=[boolean])
```

### Arguments

| Argument      | Type      | Required | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       | Default |
| ------------- | --------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- |
| `path`        | `string`  | `true`   | the path of the directory to delete                                                                                                                                                                                                                                                                                                                                                                                                                                                               |         |
| `recursive`   | `boolean` | `true`   | <p>\[default:false] whether to recursively delete the directory.<br>If falls and the directory is not empty, with throw a runtime exception</p>                                                                                                                                                                                                                                                                                                                                                   | `false` |
| `followLinks` | `boolean` | `false`  | <p>\[default:false] whether to follow symbolic links found inside the directory when deleting recursively. When false, links are<br>removed as links and the folders they point to are never touched. When true, the contents of those folders are deleted too,<br>except for a link that leads back into the directory being deleted or to a folder above it, which is removed as a link.<br>A symbolic link given as the path only has the link removed, whatever the value of followLinks.</p> | `false` |

## Examples

### Tag Syntax

```java
<bx:set delDirectory = "someDirPath" >
<bx:set recurse = true >
<bx:set directoryDelete( delDirectory, recurse ) >
```

### Additional Examples

<a href="https://try.boxlang.io/?code=eJxLySxKTS7JL6pMSc1JLUnVUFBygYkEJJZkKCloWnMBAP8NDKU%3D" target="_blank">Run Example</a>

```java
directorydelete( "DirectoryPath" );

```

### Delete a folder that contains symbolic links

A recursive delete never follows symbolic links. A link is removed as a link and the folder it points to is left alone.

```java
shared = getTempDirectory() & "linkDemoShared";
build = getTempDirectory() & "linkDemoBuild";
directoryCreate( shared );
fileWrite( shared & "/keep.txt", "keep" );
directoryCreate( build );
fileWrite( build & "/out.txt", "out" );
fileCreateSymlink( build & "/lib", shared );

directoryDelete( build, true );
writeOutput( directoryExists( build ) & " " & fileExists( shared & "/keep.txt" ) );

```

Result: false true

### Delete a symbolic link given as the path

Only the link is removed, with or without `recursive` and even when `followLinks` is true.

```java
fileCreateSymlink( build, shared );
directoryDelete( build, true );
writeOutput( fileIsSymlink( build ) & " " & fileExists( shared & "/keep.txt" ) );

```

Result: false true

### Follow symbolic links when deleting

Pass `followLinks=true` to delete the contents of the folders that links inside the directory point to as well. Use with care, the targets are emptied. A link that leads back into the folder being deleted, or to a folder above it, is removed as a link.

```java
directoryCreate( build );
fileCreateSymlink( build & "/lib", shared );

directoryDelete( build, true, true );
writeOutput( directoryExists( build ) & " " & fileExists( shared & "/keep.txt" ) );

```

Result: false false

## Related

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


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
