> For the complete documentation index, see [llms.txt](https://trizen.gitbook.io/sidef-lang/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://trizen.gitbook.io/sidef-lang/syntax_and_semantics/literals/dirhandle.md).

# DirHandle

Abstraction on a directory descriptor, to access the content of a directory:

```ruby
var dh = Dir("/my/path").open
```

Some useful methods on DirHandle objects:

```ruby
dh.read                 # read one entry as a File or a Dir object
dh.entries              # read all entries as an Array of File and Dir objects
dh.files                # read all file entries as an Array of File objects
dh.dirs                 # read all directory entries as an Array of Dir objects
dh.seek(pos)            # set the current position in the directory handle
dh.rewind               # set the current position to the beginning of the directory
dh.tell                 # returns the current position in the directory handle
dh.chdir                # change the working directory to the path of `dh`
dh.each { ... }         # iterate over each entry
dh.close                # close the directory handle
```

The special `DirHandle` type can be for checking if a given object is really a DirHandle object:

```ruby
dh.kind_of(DirHandle)    # true if `dh` is a DirHandle object
```

The directory object to which a DirHandle refers, if any, can be obtained with `dh.dir`, which may be `nil` or a `Dir` object.


---

# 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 dynamically by asking a question.

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

```
GET https://trizen.gitbook.io/sidef-lang/syntax_and_semantics/literals/dirhandle.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
