delete-old-files
v1.0.0
Published
Delete files that were last updated too long time ago.
Maintainers
Readme
delete-old-files
Delete files that were last updated too long time ago.
:cloud: Installation
# Using npm
npm install --save delete-old-files
# Using yarn
yarn add delete-old-files:clipboard: Example
const deleteOldFiles = require("delete-old-files");
const DIRECTORY_PATHS = [
`${__dirname}/directory-to-keep-clean`
]
// Delete txt files older than 3 days
deleteOldFiles({
directoryPaths: DIRECTORY_PATHS,
age: 86400 * 3, // 3 days
checkInterval: 86400, // seconds (1 day)
exclude: [
".gitignore",
"keep.txt",
"do-not-delete.txt",
/\.md$/
],
include: [
/\.txt$/
],
verbose: true,
dryRun: true, // Set to true for testing
onError: (err) => { console.error("Error occurred:", err); },
onDelete: (filePath) => { console.log("Deleted file:", filePath); },
}):memo: Documentation
deleteOldFiles(options)
Deletes the old files in the specified directories.
Params
- Object
options: The options object containing:directoryPaths(Array): An array of directory paths to scan for old files. Default is[].age(Number): The age in seconds that a file must be older than to be deleted. Default is604800(7 days).checkInterval(Number): The interval in seconds to check for old files. Default is86400(1 day). Set to0to disable periodic checks.recursive(Boolean): Whether to scan directories recursively. Default isfalse.exclude(Array): An array of file names or regex patterns to exclude from deletion. Default is[].include(Array): An array of file names or regex patterns to include for deletion. If empty, all files are included unless excluded. Default is[].verbose(Boolean): Whether to log detailed information about the process. Default isfalse.dryRun(Boolean): Iftrue, files will not be deleted, but actions will be logged. Default isfalse.onError(Function): A callback function that is called when an error occurs. Receives the error as an argument.onDelete(Function): A callback function that is called when a file is deleted. Receives the file path as an argument.
:question: Get Help
There are few ways to get help:
- Please post questions on Stack Overflow. You can open issues with questions, as long you add a link to your Stack Overflow question.
- For bug reports and feature requests, open issues. :bug:
- For direct and quick help, you can use Codementor. :rocket:
:yum: How to contribute
Have an idea? Found a bug? See how to contribute.
:sparkling_heart: Support my projects
I open-source almost everything I can, and I try to reply to everyone needing help using these projects. Obviously, this takes time. You can integrate and use these projects in your applications for free! You can even change the source code and redistribute (even resell it).
However, if you get some profit from this or just want to encourage me to continue creating stuff, there are few ways you can do it:
Starring and sharing the projects you like :rocket:
—I love books! I will remember you after years if you buy me one. :grin: :book:
—You can make one-time donations via PayPal. I'll probably buy a ~~coffee~~ tea. :tea:
—Set up a recurring monthly donation and you will get interesting news about what I'm doing (things that I don't share with everyone).
Bitcoin—You can send me bitcoins at this address (or scanning the code below):
1P9BRsmazNQcuyTxEqveUsnf5CERdq35V6
Thanks! :heart:
