folder-clean
v0.3.0
Published
[![npm version][version-image]][version-url] [![build status][travis-image]][travis-url] [![dependency status][david-image]][david-url] [![license][license-image]][license-url] [![js standard style][standard-image]][standard-url] [![downloads per month][d
Downloads
4
Readme
folder-clean
Analyzes and potentially deletes all files and folders which are older than a given date. The analyze phase has been seperated from the deletion phase. This has the benefit that we can first display the results before actually deleting them.
Getting Started
First we'll analyze all items contained in a given folder. Note that this does not delete anything yet. In this example we additionally mark empty folders as deletable.
const {
markEmptyFoldersAsDeletable,
analyzeFolderRecursive,
executeActions
} = require('folder-clean')
const { join } = require('path')
const actions = markEmptyFoldersAsDeletable(
await analyzeFolderRecursive(path, new Date('01/13/2017'), 90)
)
Where actions
contains something like the following.
[
{
itemType: Symbol(FILE),
actionType: Symbol(DELETE),
path: '~/absolute/path/to/old.txt'
}, {
// this would have gotten deleted if we didn't mark
// empty folders.
itemType: Symbol(EMPTY_DIR),
actionType: Symbol(DELETE),
path: '~/absolute/path/to/empty-folder'
}, {
itemType: Symbol(FILE),
actionType: Symbol(DELETE),
path: '~/absolute/path/to/sub-folder/old.txt'
},
itemType: Symbol(FILE),
actionType: Symbol(RETAIN),
path: '~/absolute/path/to/new.txt'
}, {
itemType: Symbol(FILE),
actionType: Symbol(RETAIN),
path: '~/absolute/path/to/sub-folder/new.txt'
}, {
itemType: Symbol(DIR),
actionType: Symbol(RETAIN),
path: '~/absolute/path/to/sub-folder'
}
]
After that, execute each given action.
await executeActions(actions)
Installation
> npm install folder-clean
(or)
> yarn add folder-clean