High-Performance Folder Size Calculator.
npm install get-folderbash
npm install get-folder
`
š Quick Start
$3
`typescript
import { FolderSize } from 'get-folder';
// Calculate folder size
FolderSize.getSize('./my-folder').then(res => {
// size is returned in BigNumber format
console.log(Folder size: ${res.size.toString()});
console.log(File count: ${res.fileCount});
console.log(Directory count: ${res.directoryCount});
console.log(Symbolic link count: ${res.linkCount});
});
`
$3
`typescript
import { FolderSize } from 'get-folder';
// Custom options
const result = await FolderSize.getSize('./my-folder', {
// Maximum depth limit
maxDepth: 5,
// Ignore file/directory patterns
ignores: [/node_modules/, /\.git/],
// Whether to include hidden files
includeHidden: false,
// Whether to include symbolic links
includeLink: true,
// Concurrency control
concurrency: 2,
// Ignore errors and continue calculation
ignoreErrors: true,
// Whether to check inodes to avoid counting hard links multiple times
inodeCheck: true,
// Error handling callback
onError: (error) => {
console.log(Error: ${error.message} at ${error.path});
// true=continue, false=stop
return true;
}
});
`
š§ API Reference
$3
Core method for calculating folder size.
#### Parameters
- folderPath (string): Path to the folder to analyze
- options (FolderSizeOptions, optional): Configuration options
#### Configuration Options
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| maxDepth | number | Infinity | Maximum traversal depth to limit directory levels |
| ignores | RegExp[] | [] | Array of file/directory patterns to ignore |
| includeHidden | boolean | true | Whether to include hidden files (simple hidden file detection, files starting with .) |
| includeLink | boolean | true | Whether to include symbolic link files (shortcuts) |
| concurrency | number | 2 | Number of concurrent operations, recommended value is 2 (appropriate adjustment can improve efficiency, not necessarily bigger is better) |
| ignoreErrors | boolean | false | Whether to ignore errors and continue calculation |
| inodeCheck | boolean | true | Whether to check inodes to avoid duplicate counting of hard links |
| onError | function | () => true | Error handling callback function, returns true to ignore errors and continue execution (affected by ignoreErrors configuration), otherwise throws exception |
#### Return Value
Returns a Promise that resolves to FolderSizeResult:
`typescript
interface FolderSizeResult {
// Total size in bytes
size: BigNumber;
// Number of files
fileCount: number;
// Number of directories
directoryCount: number;
// Number of symbolic links
linkCount: number;
}
``