JSPM

  • Created
  • Published
  • Downloads 11705
  • Score
    100M100P100Q127475F
  • 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-remove

then in your node.js app, get reference to the function like that:

var findRemoveSync = require('find-remove');

quick examples

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

var result = findRemoveSync('/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 = findRemoveSync(rootDirectory, {files: 'dump.log'});

same as above but do not delete file 'haumiblau.bak'

var result = findRemoveSync(rootDirectory, {files: 'dump.log', ignore: 'haumiblau.bak'});

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

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

delete everything inside AND including the /temp directory

just call it without options because no options means nothing is filtered.

var result = findRemoveSync('/tmp');

api

findRemoveSync(dir, options)

findRemoveSync takes any start directory and searches files from there for removal. the selection of files for removal depends on the given options. and at last, it deletes the selected files.

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 want to remove all files (but not directories).
    • extensions - this too, can be a string or an array of file extenstions you want to delete within dir
    • ignore - useful to exclude some files. again, can be a string or an array of file names you do NOT want to delete within dir

when no options are given, are undefined or null, then everything including directories are removed as if there were no filters.

todo

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

license

MIT