NODE 模块 FS-EXTRA
fs-extra模块是系统fs模块的扩展,提供了更多便利的 API,并继承了fs模块的 API。
1、复制文件
copy(src, dest, [options], callback)
示例:
var fs = require('fs-extra');
fs.copy('/tmp/myfile', '/tmp/mynewfile', function(err) {
if (err) return console.error(err)
console.log("success!")
});
fs.copy('/tmp/mydir', '/tmp/mynewdir', function(err) {
if (err) return console.error(err)
console.log("success!")
});
2、创建文件、目录
ensureFile(file, callback)
createFile(file, callback)
createFileSync(file),
ensureFileSync(file)
ensureDir(dir, callback)
ensureDirSync(dir)
示例:
var fs = require('fs-extra');
var file = '/tmp/this/path/does/not/exist/file.txt'
fs.ensureFile(file, function(err) {
console.log(err) // => null
//file has now been created, including the directory it is to be placed in
});
var dir = '/tmp/this/path/does/not/exist'
fs.ensureDir(dir, function(err) {
console.log(err) // => null
//dir has now been created, including the directory it is to be placed in
});
3、移动文件、目录
move(src, dest, [options], callback)
示例:
var fs = require('fs-extra')
fs.move('/tmp/somefile', '/tmp/does/not/exist/yet/somefile', function(err) {
if (err) return console.error(err)
console.log("success!")
})
4、写入文件
outputFile(file, data, callback)
示例:
var fs = require('fs-extra')
var file = '/tmp/this/path/does/not/exist/file.txt'
fs.outputFile(file, 'hello!', function(err) {
console.log(err) // => null
fs.readFile(file, 'utf8', function(err, data) {
console.log(data) // => hello!
})
})
5、删除文件、目录
remove(dir, callback)
示例:
var fs = require('fs-extra')
fs.remove('/tmp/myfile', function(err) {
if (err) return console.error(err)
console.log("success!")
})
fs.removeSync('/home/jprichardson')
NODE 模块 FS-EXTRA的更多相关文章
- [Nodejs] node的fs模块
fs 模块 Node.js 提供一组类似 UNIX(POSIX)标准的文件操作 API. Node 导入文件系统模块(fs).Node.js 文件系统(fs 模块)模块中的方法均有异步和同步版本,例如 ...
- Node内核基本自带模块fs 文件的读写
在node的内核中存在一些内置的模块 这些是最基本的服务端所必要的 1:node全局环境:global类似于浏览器端的window 2:文件读取模块:fs fs模块同时提供了异步和同步的方法. 'us ...
- 【node】fs模块,文件和目录的操作
检查文件是否存在,查询文件信息 fs.stat() fs.stat('./server.js', function (err, stat) { if (stat && stat.isF ...
- node的fs模块使用————node
node的fs模块使用----node fs模块是调用文件的模块. var fs=require('fs'); //引用模块. //查看文件信息 fs.stat('index.txt',functio ...
- 从官网学习Node.js FS模块方法速查
最新文档请查看仓库 https://github.com/wangduandu... 1. File System 所有文件操作提供同步和异步的两种方式,本笔记只记录异步的API 异步方式其最后一个参 ...
- Node.js FS模块方法速查
1. File System 所有文件操作提供同步和异步的两种方式,本笔记只记录异步的API 异步方式其最后一个参数是回调函数.回调函数的第一个参数往往是错误对象,如果没有发生参数,那么第一个参数可能 ...
- nodejs模块——fs模块
fs模块用于对系统文件及目录进行读写操作. 一.同步和异步 使用require('fs')载入fs模块,模块中所有方法都有同步和异步两种形式. 异步方法中回调函数的第一个参数总是留给异常参数(exce ...
- Commonjs规范及Node模块实现
前面的话 Node在实现中并非完全按照CommonJS规范实现,而是对模块规范进行了一定的取舍,同时也增加了少许自身需要的特性.本文将详细介绍NodeJS的模块实现 引入 nodejs是区别于java ...
- 模块机制 之commonJs、node模块 、AMD、CMD
在其他高级语言中,都有模块中这个概念,比如java的类文件,PHP有include何require机制,JS一开始就没有模块这个概念,起初,js通过<script>标签引入代码的方式显得杂 ...
- 【转】Commonjs规范及Node模块实现
前言: Node在实现中并非完全按照CommonJS规范实现,而是对模块规范进行了一定的取舍,同时也增加了少许自身需要的特性.本文将详细介绍NodeJS的模块实现 引入 nodejs是区别于javas ...
随机推荐
- [翻译]LVM中逻辑卷的最大大小限制
前言: 本文是对这篇博客Maximum Size Of A Logical Volume In LVM的翻译,敬请尊重原创和翻译劳动成果,那些随意转载的大爷们,好歹也自觉注明出处.谢谢! 英文原文地址 ...
- Springboot helloworld入门最经典例子
一.建立maven java项目 导入springboot包 二.配置pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0 ...
- [20181225]12CR2 SQL Plan Directives.txt
[20181225]12CR2 SQL Plan Directives.txt --//12C引入SQL PLAN Directives.12cR1版本会造成大量的动态取样,影响性能.许多人把OPTI ...
- [20180927]ora-01426.txt
[20180927]ora-01426.txt --//链接:http://www.itpub.net/thread-2105458-1-1.html1.环境:SCOTT@test01p> @ ...
- 自动化测试基础篇--Selenium获取元素属性
摘自https://www.cnblogs.com/sanzangTst/p/8375938.html 通常在做断言之前,都要先获取界面上元素的属性,然后与期望结果对比. 一.获取页面title 二. ...
- Linux内核线程kernel thread详解--Linux进程的管理与调度(十)
内核线程 为什么需要内核线程 Linux内核可以看作一个服务进程(管理软硬件资源,响应用户进程的种种合理以及不合理的请求). 内核需要多个执行流并行,为了防止可能的阻塞,支持多线程是必要的. 内核线程 ...
- 在Lua中提示UnityEngine.dll的方法
我的环境 安装最新的 EmmyLua-1.2.1及以上版本 IDEA 2017.1.2 及以上版本 关于EmmlyLua的介绍可查看我之前的文章:Lua代码提示和方法跳转 说明:本文方法摘自 Emmy ...
- Node中的模块引入机制
1.如果模块在当前目录下,可以通过下面语句将模块引入进来,注意需要使用 "./"表示当前路径 const currency = require('./currency'); ←-- ...
- 基于centOS7:新手篇→nginx安装
一.首先安装编译工具和库 #安装make zlib gcc OpenSSL yum -y install make zlib zlib-devel gcc-c++ libtool openssl op ...
- [WeChall] Training: Encodings I (Training, Encoding)
Training: Encodings I (Training, Encoding) We intercepted this message from one challenger to anothe ...