Get full details on a file or directory.
var stat = require( '@stdlib/fs/stat' );Asynchronously returns file system statistics for a file or directory.
The callback is invoked with an fs.Stats object containing methods and values describing the target path.
stat( __filename, onStat );
function onStat( error, stats ) {
if ( error ) {
throw error;
}
console.log( stats.isFile() );
console.log( stats.isDirectory() );
console.log( stats.isSymbolicLink() );
console.log( stats.size );
console.log( stats.mode );
console.log( stats.atime );
}Asynchronously returns file system statistics for a file or directory with options.
stat( __filename, {
'bigint': true
}, onStat );
function onStat( error, stats ) {
if ( error ) {
throw error;
}
console.log( stats.size );
console.log( stats.atimeNs );
}Options:
- bigint:
booleanflag indicating whether numeric values should be returned asbigint. Default:false.
stat( __filename, onStat );
function onStat( error, stats ) {
if ( error ) {
throw error;
}
console.log( stats.isFile() );
}Synchronously returns file system statistics for a file or directory.
var out = stat.sync( __filename );
if ( out instanceof Error ) {
throw out;
}
console.log( out.isFile() );
console.log( out.isSocket() );
console.log( out.size );
console.log( out.mtimeMs );Synchronously returns file system statistics for a file or directory with options.
var out = stat.sync( __filename, {
'bigint': true
});
if ( out instanceof Error ) {
throw out;
}
console.log( out.size );
console.log( out.birthtimeNs );The returned fs.Stats instance provides these type-check methods:
isFile()isDirectory()isBlockDevice()isCharacterDevice()isFIFO()isSocket()isSymbolicLink()
The returned fs.Stats instance also provides values such as fs.Stats:
dev,ino,mode,nlink,uid,gid,rdev,size,blksize,blocksatime,mtime,ctime,birthtimeatimeMs,mtimeMs,ctimeMs,birthtimeMsatimeNs,mtimeNs,ctimeNs,birthtimeNs(available whenbigint: true)
var out = stat.sync( __filename );
if ( out instanceof Error ) {
throw out;
}
console.log( out.isFile() );var stat = require( '@stdlib/fs/stat' );
var out = stat.sync( __filename );
if ( out instanceof Error ) {
throw out;
}
console.log( out.isFile() );
stat( __filename, onStat );
function onStat( error, stats ) {
if ( error ) {
throw error;
}
console.log( stats.isFile() );
console.log( stats.isDirectory() );
console.log( stats.isBlockDevice() );
console.log( stats.isCharacterDevice() );
console.log( stats.isFIFO() );
console.log( stats.isSocket() );
console.log( stats.isSymbolicLink() );
console.log( stats.size );
console.log( stats.mode );
console.log( stats.uid );
console.log( stats.gid );
console.log( stats.atimeMs );
console.log( stats.mtimeMs );
console.log( stats.ctimeMs );
console.log( stats.birthtimeMs );
}Usage: stat [options] <path>
Options:
-h, --help Print this message.
-V, --version Print the package version.
- Relative paths are resolved relative to the current working directory.
- Errors are written to
stderr. - Results are written to
stdoutas JSON.