zoukankan      html  css  js  c++  java
  • nodejs fs module

    fs.watchFile(filename[, options], listener)#
    Added in: v0.1.31
    filename <String> | <Buffer>
    options <Object>
    persistent <Boolean>
    interval <Integer>
    listener <Function>
    Watch for changes on filename. The callback listener will be called each time the file is accessed.
    
    The options argument may be omitted. If provided, it should be an object. The options object may contain a boolean named persistent that indicates whether the process should continue to run as long as files are being watched. The options object may specify an interval property indicating how often the target should be polled in milliseconds. The default is { persistent: true, interval: 5007 }.
    
    The listener gets two arguments the current stat object and the previous stat object:
    
    fs.watchFile('message.text', (curr, prev) => {
      console.log(`the current mtime is: ${curr.mtime}`);
      console.log(`the previous mtime was: ${prev.mtime}`);
    });
    These stat objects are instances of fs.Stat.
    
    If you want to be notified when the file was modified, not just accessed, you need to compare curr.mtime and prev.mtime.
    
    Note: when an fs.watchFile operation results in an ENOENT error, it will invoke the listener once, with all the fields zeroed (or, for dates, the Unix Epoch). In Windows, blksize and blocks fields will be undefined, instead of zero. If the file is created later on, the listener will be called again, with the latest stat objects. This is a change in functionality since v0.10.
    
    Note: fs.watch() is more efficient than fs.watchFile and fs.unwatchFile. fs.watch should be used instead of fs.watchFile and fs.unwatchFile when possible.
    
    
  • 相关阅读:
    Webbrowser 取消下载提示框
    The service ‘xxx’ configured for WCF is not registered with the Autofac container
    Code First 中的 TPH TPT TPC
    SQL Server 之 解锁
    导入 github 步骤
    初试 pyhton 简易采集
    js 一些小技巧
    linux 学习笔记
    lnmp 环境搭建后,pathinfo 模式支持的配制。
    windows 快捷键相关命令
  • 原文地址:https://www.cnblogs.com/mayidudu/p/5872396.html
Copyright © 2011-2022 走看看