博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
node 模块 fs-extra
阅读量:7103 次
发布时间:2019-06-28

本文共 1642 字,大约阅读时间需要 5 分钟。

TOC

  • 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')

转载于:https://www.cnblogs.com/yanan-boke/p/7772938.html

你可能感兴趣的文章
python文件读取并使用mysql批量插入
查看>>
python
查看>>
HTTPS SSL免费证书生成
查看>>
Linux下卸载和安装MySQL[rpm包]
查看>>
Xcode 自带git 使用,忽略用户数据
查看>>
title: Spring Security源码分析七:Spring Security 记住我
查看>>
【原创】图解 hotwheels
查看>>
Git提交与更新
查看>>
自定义类实现基于数组/字典Literal Syntax设置和获取数据
查看>>
iOS开发22:SandBox的结构
查看>>
java之反射构造方法
查看>>
Android studio鼠标提示功能
查看>>
PHP 浮点型运算相关问题
查看>>
laraval 安装
查看>>
创业,不投入哪儿行—助力威客加入第四次创业浪潮
查看>>
如何删除Grub引导恢复Windows引导
查看>>
Java IO:BIO和NIO区别及各自应用场景
查看>>
Google 宣布将会关闭消费者版本 Google+
查看>>
Linux 平台下的漏洞扫描器 Vuls
查看>>
使用缓存的9大误区(下)
查看>>