🌳
pt0/serverF/libFs/getDirSizeF.mts
1import { readdirSync, statSync } from 'fs'
2import path from 'path'
4export const getDirSize = (dirPath: string): number => {
5 let total = 0
6 try {
7 const entries = readdirSync(dirPath, { withFileTypes: true })
8 for (const entry of entries) {
9 const fullPath = path.join(dirPath, entry.name)
10 if (entry.isDirectory()) total += getDirSize(fullPath)
11 else if (entry.isFile()) total += statSync(fullPath).size
12 }
13 } catch {}
14 return total
17export const fmtSizeMb = (bytes: number) => `${Math.round(bytes / 1024 / 1024)}MB`