Skip to main content

Overview

The stat() method retrieves detailed metadata about a resource, including size, mode, timestamps, and whether it’s a directory.
This method is useful for checking resource existence and getting file attributes without reading content.

Method Signature

Parameters

string
required
The Viking URI of the resource to inspect

Response

string
Resource name (filename or directory name)
integer
Size in bytes (0 for directories)
integer
File mode/permissions (Unix-style)
boolean
Whether this is a directory
string
Full Viking URI of the resource
number
Last modification timestamp
number
Creation timestamp

Examples

Check if Resource Exists

Before Reading Content

Response Example

Error Responses

Resource Not Found

Use Cases

  1. Existence Check - Verify resource exists before operations
  2. Size Inspection - Check file size before reading
  3. Directory Detection - Determine if URI points to file or directory
  4. Metadata Queries - Get timestamps for change tracking

Best Practices

Use stat() before expensive operations to validate resource existence and type.
  • ls() - List directory contents
  • read() - Read file content
  • tree() - Get directory tree structure