search
尋找貓咪~QQ 地點 桃園市桃園區 Taoyuan , Taoyuan

[Node.js] fs 模組 - 取得檔案資訊

此篇文章瀏覽量: 649

檔案系統模組(fs),都提供了「非同步」和「同步」兩個版本的操作方法,此文章介紹 取得檔案資訊 的操作方式,僅示範同步(statSync)的方式。

取得檔案資訊有四個方法,分別是 fs.stat()、fs.statSync()、fs.fstat()、fs.fstatSync(),這裡僅示範fs.statSync() 方法。

「同步」取得檔案資訊:fs.statSync()

// 假設已經存在 txt/statSync.txt 檔案,取得該檔案資訊:
var fs = require('fs');
var statSync = fs.statSync('txt/statSync.txt');
console.info(statSync);

取得的資訊如下:

Stats {
  dev: 16777220,
  mode: 33188,
  nlink: 1,
  uid: 501,
  gid: 20,
  rdev: 0,
  blksize: 4096,
  ino: 111646722,
  size: 9,
  blocks: 8,
  atime: 2017-09-20T03:38:35.000Z,
  mtime: 2017-09-20T03:38:34.000Z,
  ctime: 2017-09-20T03:38:34.000Z,
  birthtime: 2017-09-20T03:38:23.000Z }

 

若覺得文章有幫助,請多分享,讓其他同好也能吸收網站技能知識。



熱門推薦

本文由 carlos-studiocom 提供 原文連結

寵物協尋 相信 終究能找到回家的路
寫了7763篇文章,獲得2次喜歡
留言回覆
回覆
精彩推薦