JSPM

  • Created
  • Published
  • Downloads 11705
  • Score
    100M100P100Q127492F
  • License MIT

recursively finds files by filter options from a start directory onwards and deletes these. useful if you want to clean up a directory in your node.js app.

Package Exports

  • find-remove

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (find-remove) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

find-delete

recursively finds files by filter options from a start directory onwards and deletes these. useful if you want to clean up a directory in your node.js app.

installation

to install find-delete, use npm:

$ npm install find-delete

quick examples

delete all *.bak and *.log files within the /temp/ directory:

var result = findRemove('/temp', {extensions: ['.bak', '.log']});

the return value 'result' is a json object with successfully deleted files. if you output result to the console, you will get something like this:

{
    '/tmp/haumiblau.bak': true,
    '/tmp/dump.log': true 
}

delete all files called 'dump.log' within the /temp/ directory and any of its subfolders:

var result = findRemove(rootDirectory, {files: 'dump.log'});

delete recursively all files called 'dump.log' AND also all files with the extension '.dmp' within /temp/:

var result = findRemove('/tmp', {files: 'dump.log', extension: '.dmp'});

delete everything inside AND including the /temp directory

just call it without parameters so that there are no filters:

var result = findRemove('/tmp', null);

or there is a nicer function for your majesty:

var result = removeAll('/tmp');

api

findRemove(dir, options)

findRemove takes any start directory and searches files from there for removal. the selection of files for removal depends on the given options.

arguments

  • dir - any directory to search for files for deletion
  • options - currently two properties are supported:
    • files - can be a string or an array of files you want to delete within dir. also *.* is allowed here if you all files.
    • extensions - this too, can be a string or an array of file extenstions you want to delete within dir

when no options are given, everything is removed as if there were no filters.

removeAll(dir)

removeAll is just a convenient function and does the same like findRemove(dir, null)

it deletes everything including dir in cold blood. you have been warned.

arguments

  • dir - any directory to delete with all its subfolders and files within.

todo

  • add more filtering options (combinations, regex, etc.)
  • have an asynchronous solution

license

MIT