DirEntry
DirEntry objects represent individual entries within a directory. They are
returned by the entries() function and the
Path.entries() method.
DirEntry objects are records with information about a directory entry, providing access to the entry's path, name, and file type.
Creating DirEntry Objects
DirEntry objects are created by iterating over directory entries:
# Iterate and get DirEntry objects
for entry = entries /home/user/docs
echo "$(entry.name) - $(entry.type)"
Fields
path
Returns the full path to the directory entry as a Path object.
Platform-Specific Fields
Unix-Only Fields
The following fields are only available on Unix systems:
ino
The inode number of the file system entry.
type
Returns the file type as a sym, or
nil if the type cannot be determined.
Possible values when present:
| Value | Description |
|---|---|
:file: |
Regular file |
:dir: |
Directory |
:symlink: |
Symbolic link |
:fifo: |
Named pipe (FIFO) |
:char_device: |
Character device |
:block_device: |
Block device |
:socket: |
Unix domain socket |
for entry = entries .
if entry.type == :dir:
echo "Directory: $(entry.name)"
else if entry.type == :file:
echo "File: $(entry.name)"
else if entry.type == nil:
echo "Unknown type: $(entry.name)"
Usage Examples
Basic Iteration
Collecting to Array
# Get all entries as an array
let all_entries = [...entries "."]
echo "Found $(all_entries.len) entries"
Working with Paths
for entry = entries ./src
# entry.path is a Path object
let full_path = entry.path
echo "Path: $full_path"
# Can use Path methods
if full_path.exists()
echo " Confirmed: exists"