Reap old files from directories
npm install tmp-reaper
var Reaper = require('tmp-reaper');
var reaper = new Reaper({
threshold: '1 day',
every: '1 hour'
});
reaper.watch('/some/directory').start();
Create a Reaper object.
var Reaper = require('tmp-reaper');
var reaper = new Reaper(options);
threshold
{string | integer} maximum lifetime of files (defaults to7days
).recursive
{boolean} reap files in subdirectories (defaults tofalse
).keepEmptyDirs
{boolean} preserve empty subdirectories (defaults tofalse
).every
{string | integer} period of time between each files check. If not provided, directories will be reaped only once.filetime
{string} filetime to use as reference. Can beatime
,mtime
orctime
. (defaults tomtime
)pattern
{string | regex} pattern that the filename has to match, else it will be skipped (optional)
Time format can be either a number of milliseconds or a string. String format is pretty permissive as it only extract numbers followed by a text, with anything in-between.
Time unit | format |
---|---|
second | s, sec, second, seconds |
minute | m, min, minute, minutes |
hour | h, hour, hours |
day | d, day, days |
Example :
var options = {
threshold: '7 day and 2.5 hours',
every: '1h20m30s'
}
delete(filepath, stats)
when a file has been deleted.error(err)
when an error occurs.
watch(dir)
add a directory to be watched for old files.unwatch(dir)
stop watching the given directory.start()
start reaping.stop()
stop reaping.