Skip to content

Instantly share code, notes, and snippets.

@krutoo
Created February 14, 2026 11:56
Show Gist options
  • Select an option

  • Save krutoo/3c8a7a73a7655649837940218fd92067 to your computer and use it in GitHub Desktop.

Select an option

Save krutoo/3c8a7a73a7655649837940218fd92067 to your computer and use it in GitHub Desktop.
Get mtime for directory based on contained files
import { readdirSync, statSync } from 'node:fs';
import path from 'node:path';
export function getMtimeDeep(dirname: string): number {
const files = readdirSync(dirname, { recursive: true });
let max = 0;
for (const filename of files) {
const stat = statSync(path.join(dirname, filename as string));
if (stat.mtimeMs > max) {
max = stat.mtimeMs;
}
}
return max;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment