Socket
Socket
Sign inDemoInstall

fs-extend

Package Overview
Dependencies
0
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    fs-extend

提供扩展原生fs模块不支持的功能


Version published
Weekly downloads
6
increased by100%
Maintainers
1
Install size
14.1 kB
Created
Weekly downloads
 

Readme

Source

fs-extend

提供扩展原生fs模块不支持的功能

Usage

npm i fs-extend -S
const fsEx = require('fs-extend')
fsEx.mkdir('./1/2/3/4/5/6/7/8/9', (err) => {
  if (err) {
    return console.error(err)
  }
  console.log('ok')
})

Function

mkdir
  • path <string> 目录路径
  • callback <Function>
    • err <Error>

递归建立目录

fsEx.mkdir('./1/2/3/4/5/6/7/8/9', (err) => {
  if (err) {
    return console.error(err)
  }
  console.log('ok')
})
mkdirSync

同步递归建立目录

  • path <string>
try {
  fsEx.mkdirSync('./1/2/3/4/5/6/7/8/9')
  console.log('ok')
} catch (err) {
  console.error(err)
}
rm

删除目录及子目录

  • path <string> 目录路径
  • callback <Function>
    • err <Error>
fsEx.rm('./1', (err) => {
  if (err) {
    return console.error(err)
  }
  console.log('ok')
})
rmSync

同步删除目录及子目录。

  • path <string> 删除的目录
try {
  fsEx.rmSync('./1')
  console.log('ok')
} catch (err) {
  console.error(err)
}
find

查找path目录及子目录下匹配pattern的文件和目录。

  • path <string> 查找的目录。
  • pattern <string> | <RegExp> 查找的模式。
  • callback <Function>
    • err <Error>
    • result <string[]> 查找的结果。
fsEx.find('.', '.jpg', (err, result) => {
  if (err) {
    return console.error(err)
  }
  console.log(result)
})
findSync

同步查找path目录及子目录下匹配pattern的文件和目录。

  • path <string> 目录路径。
  • pattern <string> | <RegExp> 查找的模式。
try {
  const result = fsEx.findSync('.', '.jpg')
  console.log(result)
} catch (err) {
  console.error(err)
}
listFiles

列出目录及子目录下所有文件。

  • path <string>
  • callback <Function>
    • err <Error>
    • result <string[]> 文件列表。
fsEx.listFiles('.', (err, result) => {
  if (err) {
    return console.error(err)
  }
  console.log(result)
})
listFilesSync

同步列出目录及子目录所有文件。

try {
  const result = fsEx.listFilesSync('.')
  console.log(result)
} catch (err) {
  console.error(err)
}

empty

判断目录是否空目录

fsEx.empty('.', (err, isEmpty) => {
  if (err) {
    return console.error(err)
  }
  console.log('isEmpty: %s', isEmpty)
})
emptySync

同步判断目录是否空目录。

  • path <string>
try {
  const isEmpty = fsEx.emptySync('.')
  console.log('isEmpty: %s', isEmpty)
} catch (err) {
  console.error(err)
}

Keywords

FAQs

Last updated on 04 Jul 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc