0.3.0 • Published 7 years ago

folder-clean v0.3.0

Weekly downloads
-
License
MIT
Repository
-
Last release
7 years ago

folder-clean

npm version build status dependency status license js standard style downloads per month

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

License

MIT

0.3.0

7 years ago

0.2.0

7 years ago

0.1.0

7 years ago