# qiao-file

> nodejs file tool

Latest version **5.0.6** (published 2025-12-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install qiao-file
pnpm add qiao-file
yarn add qiao-file
bun add qiao-file
```

## Health

**Score 50/100 (C)** — status: stable.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

## Facts

| | |
|---|---|
| Version | 5.0.6 |
| Published | 2025-12-23 |
| First published | 2022-04-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 22.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | uikoo9 |
| Maintainers | npm_insistime |
| Keywords | fs, tool |

## Links

- npm: https://www.npmjs.com/package/qiao-file
- Repository: https://github.com/uikoo9/qiao-nodejs
- Homepage: https://code.vincentqiao.com/#qiao-file
- Issues: https://github.com/uikoo9/qiao-nodejs/issues
- npm.io page: https://npm.io/package/qiao-file

## Dependencies (3)

- [debug](https://npm.io/package/debug.md) ^4.4.3
- [fs-extra](https://npm.io/package/fs-extra.md) ^11.3.3
- [qiao-encode](https://npm.io/package/qiao-encode.md) ^5.0.6

## 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

- 5.0.6 (latest) — 2025-12-23
- 5.0.5 — 2025-12-23
- 5.0.1 — 2025-09-18
- 5.0.0 — 2025-07-25
- 4.9.8 — 2025-07-09
- 4.9.4 — 2025-03-18
- 4.7.4 — 2024-12-05
- 4.7.2 — 2024-12-04
- 4.7.1 — 2024-12-04
- 4.5.5 — 2024-04-30
- 4.5.4 — 2024-04-30
- 4.5.3 — 2024-04-30
- 4.5.1 — 2024-03-07
- 4.4.2 — 2024-02-17
- 4.3.5 — 2024-01-11
- … 65 more at https://npm.io/package/qiao-file/versions

## README

## qiao-file

[![npm version](https://img.shields.io/npm/v/qiao-file.svg?style=flat-square)](https://www.npmjs.org/package/qiao-file)
[![npm downloads](https://img.shields.io/npm/dm/qiao-file.svg?style=flat-square)](https://npm-stat.com/charts.html?package=qiao-file)

nodejs 下文件相关封装

1. [Node.js-开发实践：高性能 FS](https://blog.vincentqiao.com/nodejs-fs)
2. [Node.js-开发实践：使用健壮的 FS](https://blog.vincentqiao.com/nodejs-fs-extra)

## install

安装

```shell
npm i qiao-file
```

## use

使用

```javascript
// cjs
const { isExists } = require('qiao-file');

// mjs
import { isExists } from 'qiao-file';
```

## api

### extname

获取文件的后缀

- filePath
  - 类型: string
  - 说明: 文件地址
- return
  - 类型: string
  - 说明: 文件后缀，例如.js

```javascript
const res = extname(filePath);
```

### isExists

判断文件或者文件夹是否存在

- fpath
  - 类型: string
  - 说明: 文件或者文件夹地址
- return
  - 类型: boolean
  - 说明: 结果
  - true: 存在

```javascript
const res = await isExists(fpath);
```

### isDir

判断文件路径是否为文件夹

- fpath
  - 类型: string
  - 说明: 文件或者文件夹地址
- return
  - 类型: boolean
  - 说明: 结果
  - true: 是文件夹

```javascript
const res = await isDir(fpath);
```

### cp

复制文件或文件夹

- src
  - 类型: string
  - 说明: 文件或文件夹地址
- dest
  - 类型: string
  - 说明: 目标文件或文件夹地址，如果 dest 存在，默认会覆盖
- return
  - 类型: boolean
  - 说明: 结果
  - true: 成功

```javascript
const res = await cp(src, dest);
```

### mv

移动文件或文件夹

- src
  - 类型: string
  - 说明: 文件或文件夹地址
- dest
  - 类型: string
  - 说明: 目标文件或文件夹地址，如果 dest 存在，默认会覆盖
- return
  - 类型: boolean
  - 说明: 结果
  - true: 成功

```javascript
const res = await mv(src, dest);
```

### rm

删除文件或文件夹

- path
  - 类型: string
  - 说明: 文件或文件夹地址
- return
  - 类型: boolean
  - 说明: 结果
  - true: 成功

```javascript
const res = await rm(path);
```

### mkdir

创建文件夹

- dirpath
  - 类型: string
  - 说明: 文件夹地址
- return
  - 类型: boolean
  - 说明: 结果
  - true: 成功

```javascript
const res = await mkdir(dirpath);
```

### readdir

读取文件夹内容

- dirpath
  - 类型: string
  - 说明: 文件夹地址
- return
  - 类型: string[]
  - 说明: dirpath 下的文件或文件夹路径
  - ```javascript
    ['path', ...]
    ```

```javascript
const res = await readdir(dirpath);
```

### lsdir

列出文件夹下所有的文件和文件夹路径

- dirpath
  - 类型: string
  - 说明: 文件夹地址
- return
  - 类型: object
  - 说明: dirpath 下的文件或文件夹路径
  - ```javascript
    {
      files: [
        {
          name: 'index.js',
          path: '/path/to/index.js',
        },
        ...
      ],
      folders: [
        {
          name: '1',
          path: '/path/to/1',
        },
        ...
      ],
    }
    ```

```javascript
const res = await lsdir(dirpath);
```

### lstree

列出文件夹下所有的文件和文件夹信息，以树的方式

- dirpath
  - 类型: string
  - 说明: 文件夹地址
- ignores
  - 类型: string[]
  - 说明：需要过滤的路径
- return
  - 类型: object[]
  - 说明: dirpath 下的文件和文件夹信息，以树的方式
  - ```javascript
    [
      {
        children: [],
        name: 'filename',
        path: '',
      },
    ];
    ```

```javascript
const dirpath = 'xx';
const ignores = ['node_modules', 'is-'];
const res = await lstree(dirpath, ignores);
```

### readFile

读取文件内容

- filePath
  - 类型: string
  - 说明: 文件地址
- return
  - 类型: string
  - 说明: 文件内容

```javascript
const res = await readFile(filePath);
```

### readFileLineByLine

按行读取文件

- filePath
  - 类型: string
  - 说明: 文件地址
- onLine
  - 类型: function
  - 说明: 每行的回调函数
- onClose
  - 类型: function
  - 说明: 整个文件读取完毕的回调函数

```javascript
readFileLineByLine(filePath, onLine, onClose);
```

### writeFile

写文件

- filePath
  - 类型: string
  - 说明: 文件地址
- content
  - 类型: string
  - 说明: 文件内容
- return
  - 类型: boolean
  - 说明: 结果
  - true: 成功

```javascript
const res = await writeFile(filePath, content);
```

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