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 ...
随机推荐
- linux 命令之netstat
转自:http://www.maomao365.com/?p=699 linux 命令之netstat 在linux中netstat命令的作用是查看TCP/IP网络当前所开放端口,所对应的本地和外地端 ...
- Spring扫面路径配置不全导致异常 org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): 的原因
运行Junit测试类 package cn.bgodata.x.zero.service; import org.junit.Test; import org.junit.runner.RunWith ...
- SQL SERVER查询字段在哪个表里
); SET @ColumnName='字段名的模糊匹配'; SELECT 表名=D.NAME, 表说明 THEN ISNULL(F.VALUE, ' ') ELSE ' ' END, 字段序号 = ...
- http网站转换成https网站
https,https的本地测试环境搭建,asp.net结合https的代码实现,http网站转换成https网站之后遇到的问题 一:什么是https SSL(Security Socket ...
- numpy中stack、hstack,vstack,dstack函数功能解释
https://blog.csdn.net/Riverhope/article/details/78922006 https://blog.csdn.net/ygys1234/article/deta ...
- centos7 下安装Apache2+MariaDB+PHP5过程详解
1.启用Apache2 Centos7默认已经安装httpd服务,只是没有启动.如果你需要全新安装,可以 yum install -y httpd 启动服务:systemctl start httpd ...
- python mysql数据库操作
一.pymysql 模块安装(本文博客推荐:https://www.cnblogs.com/clschao/articles/10023248.html) pip3 install pymysql 二 ...
- postgreSQL 应用case when的例子
selectname,md5(indvl_id_nbr) as indvl_id_nbr,case when char_length(indvl_id_nbr)=18 or char_length(i ...
- php面试题整理(二)
索引,desc 和explain unset只是删除了变量名
- SpringBoot注册登录(三):注册--验证账号密码是否符合格式及后台完成注册功能
SpringBoot注册登录(一):User表的设计点击打开链接SpringBoot注册登录(二):注册---验证码kaptcha的实现点击打开链接 SpringBoot注册登录(三):注册 ...