當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


node.js stats.ino用法及代碼示例

stats.ino屬性是fs.Stats類的內置應用程序編程接口,用於獲取文件係統指定的文件的“Inode”號。

用法:

stats.ino;

參數:此屬性沒有任何參數。

返回值:它返回一個數字或BigInt值,該值表示文件係統指定的文件的“Inode”號。

以下示例說明了Node.js中stats.ino屬性的使用:



範例1:

// Node.js program to demonstrate the    
// stats.ino Property 
  
// Accessing fs module 
const fs = require('fs'); 
  
// Calling stats.ino property from 
// fs.Stats  class 
// For files using stat 
fs.stat('./filename.txt', (err, stats) => { 
    if (err) throw err; 
    console.log("using stat:the \"Inode\" "
        + "number of the file is  " + stats.ino); 
}); 
  
// Using lstat 
fs.lstat('./filename.txt', (err, stats) => { 
    if (err) throw err; 
    console.log("using lstat:the \"Inode\" "
        + "number of the file is  " + stats.ino); 
}); 
  
// For directories using stat 
fs.stat('./', (err, stats) => { 
    if (err) throw err; 
    console.log("using stat:the \"Inode\" "
        + "number of the file is  " + stats.ino); 
}); 
  
//using lstat 
fs.lstat('./', (err, stats) => { 
    if (err) throw err; 
    console.log("using lstat:the \"Inode\" "
    + "number of the file is  " + stats.ino); 
});

輸出:

using stat:the "Inode" number of the file is  1125899907737972
using lstat:the "Inode" number of the file is  1125899907737972
using stat:the "Inode" number of the file is  14918173765820528
using lstat:the "Inode" number of the file is  14918173765820528

範例2:

// Node.js program to demonstrate the    
// stats.ino Property 
  
// Accessing fs module 
const fs = require('fs').promises; 
   
// Calling stats.ino property from 
// fs.Stats class 
(async() => { 
  const stats = await fs.stat('./filename.txt'); 
   
  // Using stat synchronous 
  console.log("The \"Inode\" number "
    + "of the file is  "+stats.ino); 
})().catch(console.error)

輸出:

The "Inode" number of the file is  1125899907737972

注意:上麵的程序將通過使用以下命令進行編譯和運行node filename.js命令並正確使用file_path。

參考: https://nodejs.org/api/fs.html#fs_stats_ino




相關用法


注:本文由純淨天空篩選整理自gekcho大神的英文原創作品 Node.js | stats.ino Property。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。