# emptydir

> recursively delete files while preserving directories

Latest version **0.0.0** (published 2014-07-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install emptydir
pnpm add emptydir
yarn add emptydir
bun add emptydir
```

Provides the command `emptydir`.

## 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.0 |
| Published | 2014-07-27 |
| First published | 2014-07-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Gocho Mugo |
| Maintainers | gochomugo |
| Keywords | delete, directories, empty, files, graceful, preserve, remove, recursive |

## Links

- npm: https://www.npmjs.com/package/emptydir
- Repository: https://github.com/GochoMugo/emptydir
- Issues: https://github.com/GochoMugo/emptydir/issues
- npm.io page: https://npm.io/package/emptydir

## 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.0 (latest) — 2014-07-27
- 0.0.0-beta — 2014-07-23
- 0.0.0-alpha — 2014-07-21

## README

# emptydir [![Build Status](https://travis-ci.org/GochoMugo/emptydir.svg?branch=master)](https://travis-ci.org/GochoMugo/emptydir)

You now get to delete files recursively while preserving the directories from [Node.Js][nodejs] and your terminal.

## installation ##

You require [npm][npm] to install/download this module.

`npm install emptydir`

If you wish to install it globally on your machine:

`npm install -g emptydir`

The module `emptydir` will be added in the correct *node_modules* directory and the command `emptydir` will be added to your *terminal*.

## usage ##

### from Node.Js (programmatic) ###

```js

var emptydir = require('emptydir');

/* 
* Assuming the variable 'my_path' holds a path to
* a folder on your machine
*/

/*
* errs will be an array with all the errors that occurred
* Otherwise null on success
*/
emptydir.emptyDir(my_path, function (errs) {
    if (errs) {
        errs.forEach(function (err) {
            console.log(err.path + " failed due to " + err.code);
        });
    }
});

/*
* callback is called per file(and not directory) being worked on.
* err is null on success
*/
emptydir.emptyDirs(my_path, function (err, path) {
    if (err) {
        console.log("Failed: " + path);
    }
    console.log("Success: " + path);
});

/*
* Synchronous. Returns an array of all the errors that occurred while
* working on the files in the directory.
* On success, returns an empty array. Thus it is safe to immediately
* loop through the errors in the array.
*/
errs = emptydir.emptyDirsSync(my_path);
errs.forEach(function () {
    console.log(err.path + " failed due to " + err.code);
});
```

#### notes ####

> By saying **working on a file**, we mean to try and remove it.

**All** of the methods:

1. If the path passed is a file, it is simply deleted. It's '**not** amust the path points to a directory.
2. Symbolic links are not dereferenced. They are deleted equally as files.

Any of the **Asynchronous** methods:

1. If a callback is **not** passed, the methods will complete as would have if callback was passed.

<hr>

**emptydir.emptyDir(path [, callback])**

1. Callback is called only **once** after the working on the files is complete.
2. On error, a list of **all** errors occurred during the recursive removal is passed to the callback.
3. On success, error will be `null`

<hr>

**emptydir.emptyDirs(path [, callback])**

1. The callback is called **each** time a file is worked on.
2. **path** of the file worked on is **always** passed as the second argument to the callback on both success and error.

<hr>

**emptydir.emptyDirsSync(path)**

1. The return value will always be an array. Thus no need to test for that.

> **Note:** The idea of the methods is to keep going even when an error is encountered. This ensures we remove as much files as possible.

### from your terminal (commandline) ###

```bash
# output help info about available options.
$ emptydir -h
$ emptydir --help
...
# show the version number of emptydir installed.
$ emptydir --version
...
# empty directoryA
$ emptydir directoryA
...
# empty directoryA and directoryB
$ emptydir directoryA directoryB
...
# be verbose while emptying directoryA
$ emptydir -v directoryA
$ emptydir --verbose directoryA
```

#### notes ####

1. If a regular file, instead of a directory, is passed to `emptydir` it will just be deleted, if possible.
2. **Verbose** option is **unstable** and may gave you *false* errors. That is, `emptydir` may remove some files but the *commandline runner* may report them back as failed.

## version info ##

|Aspect|Detail|
|------|------:|
|version|0.0.0|
|nodejs|0.10.\*, 0.8.\*|
|dependencies|none|
|last updated|28th July, 2014|

<!-- > A different [version][version]?-->

## contribution ##

[Fork][fork] this repo, hack it and send a Pull Request. Please try and include a test as in the tests directory.

If you encounter a bug, even if you could fix it yourself (*a pull request would be better in this case*), please create an [issue].

Also some geek talk is appreciated at [@MUGO_GOCHO][tweet].

## license #

This source code is licensed under the [MIT][MIT] license.

[nodejs]:https://nodejs.org "NodeJs Homepage"
[npm]:https://npmjs.org "Node Package Manager"
<!--[version]:https://github.com/GochoMugo/emptydir "All Versions"-->
[fork]:https://github.com/GochoMugo/emptydir "Fork this repo"
[issue]:https://github.com/GochoMugo/emptydir/issues "Create an issue"
[tweet]:https://twitter.com/MUGO_GOCHO "Tweet me"
[MIT]:https://github.com/GochoMugo/emptydir/blob/master/LICENSE  "Read the License"

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