# fs-cleaner

> 批量删除文件操作工具(库)

Latest version **1.0.9** (published 2021-01-23) · ISC license · 0 weekly downloads

## Install

```sh
npm install fs-cleaner
pnpm add fs-cleaner
yarn add fs-cleaner
bun add fs-cleaner
```

Provides the command `fs-cleaner`.

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.9 |
| Published | 2021-01-23 |
| First published | 2020-10-19 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 5 |
| Unpacked size | 123.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | ritjc |
| Maintainers | ritjc |
| Keywords | cli, fs, file, clean, delete |

## Links

- npm: https://www.npmjs.com/package/fs-cleaner
- Repository: https://github.com/cjtir123/fs-cleaner
- Homepage: https://github.com/cjtir123/fs-cleaner#readme
- Issues: https://github.com/cjtir123/fs-cleaner/issues
- npm.io page: https://npm.io/package/fs-cleaner

## Dependencies (5)

- [colors](https://npm.io/package/colors.md) ^1.4.0
- [lodash](https://npm.io/package/lodash.md) ^4.17.20
- [shelljs](https://npm.io/package/shelljs.md) ^0.8.4
- [commander](https://npm.io/package/commander.md) ^6.1.0
- [micromatch](https://npm.io/package/micromatch.md) ^4.0.2

## Alternatives

- [unionfs](https://npm.io/package/unionfs.md) — 2.2M weekly downloads
- [path-starts-with](https://npm.io/package/path-starts-with.md) — 35.9K weekly downloads
- [redzip](https://npm.io/package/redzip.md) — 1.2K weekly downloads
- [vscode-anymatch](https://npm.io/package/vscode-anymatch.md) — 848 weekly downloads
- [@ledgerhq/coin-filecoin](https://npm.io/package/@ledgerhq/coin-filecoin.md) — 793 weekly downloads

## Recent versions

- 1.0.9 (latest) — 2021-01-23
- 1.0.8 — 2021-01-23
- 1.0.6 — 2020-10-26
- 1.0.5 — 2020-10-22
- 1.0.4 — 2020-10-22
- 1.0.3 — 2020-10-20
- 1.0.2 — 2020-10-20
- 1.0.1 — 2020-10-19

## README

# 文件批量清理工具（fs-cleaner）

  批量删除文件夹中的文件，很方便去精简优化文件夹。

# 清理规则配置
使用前有必要先了解清理规则配置：
* 支持glob模式匹配
  <table>
    <tr><td>通配符</td><td>描述</td></tr>
    <tr><td>*</td><td>匹配任意数量的字符包括空字符, 相对正则表达的 .*</td></tr>
    <tr><td>?</td><td>匹配一个字符串,相对正则表达的 .</td></tr>
    <tr><td>[...]</td><td>匹配指定范围内的字符串，类似于正则表达式中的[]。如果[]中的第一个字符串是!或者^，则匹配不在范围内的任意字符串。如：[abc] 匹配任意一个包含的字符; [a-z] 匹配任意一个给定范围的字符; [!abc] 不匹配任意一个包含的字符; [!a-z] 不匹配任意一个给定范围的字符	</td></tr>
    <tr><td>**</td><td>匹配任意数量的字符包括空字符（包括路径分隔符）</td></tr>
    <tr><td>!(pattern|pattern)</td><td>匹配除了()内以外的pattern</td></tr>
    <tr><td>?(pattern|pattern)</td><td>匹配至多一个()内的pattern</td></tr>
    <tr><td>+(pattern|pattern)</td><td>匹配至少一个()内的pattern</td></tr>
    <tr><td>*(pattern|pattern)</td><td>匹配任意个()内的pattern</td></tr>
    <tr><td>@(pattern|pattern)</td><td>精确匹配()内的其中一个pattern</td></tr>|  
  </table>


* 开始位都是相对被操作文件夹的，支持两种方式：
  1. glob模式如` '**/1.txt' `
  2. 使用相对路径方式如` 'test/1.txt' ` 、 `'./test/1.txt'`

案例：
```
[
  '**/1.txt',
  '**/abc/1.txt',
  '**/abc/**/1.txt',
  '**/abc/**/def/1.txt',
  '**/abc/**/*.js',
  '**/abc/**/*.html',
  './test.txt',
  'test1/test2/*',
  '**/test1/test3/**/*.@(md|txt)'
]

```

# 使用方式
* 全局安装（支持命令行工具）``` npm install fs-cleaner -g ```

  如：清理当前目录下规则(['**/abc/test.@(md|txt)', './test/test.js'])匹配的文件
  ```
  fs-cleaner -r **/abc/test.@(md|txt),./test/test.js
  ```
  支持配置参数：
  1. -d 可选，需要清理的目录，默认值是当前命令执行的目录
  2. -r 必选，表示配置规则，多个规则用逗号分隔，也可以指向只配置文件（见-c 参数说明）
  3. -c 可选，表示支持规则配置（json或js）文件，则在-r 参数值应指向当前（命令执行）目录下的配置文件路径


* 项目中安装使用 ``` npm install fs-cleaner --save ```

  ``` javascript

    //默认导出的是一个返回Promise值的函数

    var fsCleanerHandle = require('fs-cleaner').default 
    fsCleanerHandle({targetPath: '/user/test', targetRegList: ['**/abc/test.@(md|txt)', './test/test.js']}) // targetPath 需清理的目录 ，targetRegList 清理规则配置

    // 支持es6导入 
    import fsCleanerHandle from 'fs-cleaner'

    async function main () {
      // 批量删除/user/test文件夹下的文件
      await fsCleanerHandle({targetPath: '/user/test', targetRegList: ['**/abc/test.@(md|txt)', './test/test.js']}) 
    }

    try{
      main()
    }catch(err) {
      console.error(err)
    }
    



  ```

---
_Source: https://npm.io/package/fs-cleaner · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
