# 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: 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://trizen.gitbook.io/sidef-lang/syntax_and_semantics/literals/dirhandle.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.
