# fs-path

> file and directory op libs, find, findSync, mkdir, mkdirSync, copy, copySync, remove, removeSync, writeFile, writeFileSync

Latest version **0.0.25** (published 2020-10-07) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.25 |
| Published | 2020-10-07 |
| First published | 2015-03-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 12.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | pillys |
| Maintainers | pillys |
| Keywords | fs-path, file, directory |

## Links

- npm: https://www.npmjs.com/package/fs-path
- Repository: https://github.com/pillys/fs-path
- Issues: https://github.com/pillys/fs-path/issues
- npm.io page: https://npm.io/package/fs-path

## Dependencies (2)

- [async](https://npm.io/package/async.md) ~0.9.0
- [shell-escape](https://npm.io/package/shell-escape.md) ^0.2.0

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

- 0.0.25 (latest) — 2020-10-07
- 0.0.24 — 2018-02-18
- 0.0.23 — 2016-11-24
- 0.0.22 — 2015-03-20
- 0.0.21 — 2015-03-18
- 0.0.20 — 2015-03-18
- 0.0.19 — 2015-03-17
- 0.0.18 — 2015-03-17
- 0.0.17 — 2015-03-17
- 0.0.16 — 2015-03-17
- 0.0.15 — 2015-03-16
- 0.0.14 — 2015-03-16
- 0.0.13 — 2015-03-16
- 0.0.11 — 2015-03-16
- 0.0.10 — 2015-03-16
- … 9 more at https://npm.io/package/fs-path/versions

## README

fs-path
========
[![Build Status](https://secure.travis-ci.org/pillys/fs-path.png)](http://travis-ci.org/pillys/fs-path)

---

### find(path [,filter] [,callback])

Recurcively scan files or scan files by a filter.

Callback break tow arguments: err, list

```js
var fsPath = require('fs-path');

fsPath.find('/usr/local', function(err, list){
  console.log(list.dirs);
  console.log(list.files);
});
```

The value list is an object has two keys:

```js
{
  dirs: [
    '/usr/local/test'
    '/usr/local/test/abc'
  ],
  files: [
    '/usr/local/aaa.png',
    '/usr/local/test/bbb.gif',
    '/usr/local/test/abc/ddd.html'
  ]
}
```

If you set a filter to map the files or directories, you can do like this:

```js
var fsPath = require('fs-path');

fsPath.find('/usr/local', function(filepath, stats, filename){
  if(stats === 'file' && /\.png$/.test(filename)){
    return false;
  }
  return true;
}, function(err, list){
  console.log(list.dirs);
  console.log(list.files);
});
```

filter has 3 arguments:

* filepath: the full path of the file or directory
* stats: the type of file or directory, has two value: file, directory
* filename: the name of the file or directory

It will return the list:

```js
{
  dirs: [
    '/usr/local/test'
    '/usr/local/test/abc'
  ],
  files: [
    '/usr/local/test/bbb.gif',
    '/usr/local/test/abc/ddd.html'
  ]
}
```

### findSync(path[ ,filter])

Sync version of find(). Throws exception on error.


### mkdir(path[, callback])

Recursively make, if the parent path not exists, it'll create the directory automatically.

```js
var fsPath = require('fs-path');

fsPath.mkdir('/usr/local/test1/test2/test3', function(err){
  console.log('ok');
});
```

### mkdirSync(path[ ,pattern])

Sync version of mkdir(). Throws exception on error.


### copy(from, dist[, callback])

Copy a file or directory to other path, if the parent path not exists, it'll create the directory automatically.

```js
var fsPath = require('fs-path');

fsPath.copy('/usr/local/test1/test2/test3', '/usr/local/aaaa', function(err){
  console.log('ok');
});
```

### copySync(path[ ,pattern])

Sync version of copy(). Throws exception on error.


### remove(path[, callback])

Delete a file or directory.

```js
var fsPath = require('fs-path');

fsPath.remove('/usr/local/test1/test2/test3', function(err){
  console.log('ok');
});
```

### removeSync(path)

Sync version of remove(). Throws exception on error.


### writeFile(path, content[, encoding][, callback])

Write a file a file or directory.

Encoding is optional, default is 'utf-8'.

```js
var fsPath = require('fs-path');

fsPath.writeFile('/usr/local/1.html', content function(err){
  console.log('ok');
});
```

### writeFileSync(path, content[, encoding])

Sync version of writeFile(). Throws exception on error.

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