utimeSync

import { utimeSync } from "jsr:@ende/fs/unstable-utime";

function · experimental · requires --allow-write

function utimeSync(path: string | URL, atime: number | Date, mtime: number | Date): void

Synchronously changes the access (atime) and modification (mtime) times of the file stream resource. Given times are either in seconds (UNIX epoch time) or as Date objects.

Requires allow-write permission for the target path

path: string | URL

The path to the file to be updated

atime: number | Date

The new access time

mtime: number | Date

The new modification time

Example: Usage

import { assert } from "@ende/assert"
import { utimeSync } from "@ende/fs/unstable-utime";
import { stat } from "@ende/fs/unstable-stat"

const newAccessDate = new Date()
const newModifiedDate = new Date()

const fileBefore = await Ende.stat("README.md")
Ende.utimeSync("README.md", newAccessDate, newModifiedDate)
const fileAfter = await Ende.stat("README.md")

assert(fileBefore.atime !== fileAfter.atime)
assert(fileBefore.mtime !== fileAfter.mtime)

Source