https://github.com/pepkorit/node-util-fileclean
Basic nodejs utility script for cleaning up old files via a glob
https://github.com/pepkorit/node-util-fileclean
cleanup node oldfiles script
Last synced: 6 months ago
JSON representation
Basic nodejs utility script for cleaning up old files via a glob
- Host: GitHub
- URL: https://github.com/pepkorit/node-util-fileclean
- Owner: PepkorIT
- Created: 2017-05-24T18:28:44.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-05-25T05:46:47.000Z (over 8 years ago)
- Last Synced: 2025-02-02T15:33:50.354Z (about 1 year ago)
- Topics: cleanup, node, oldfiles, script
- Language: TypeScript
- Size: 9.77 KB
- Stars: 1
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# node-util-fileclean
Basic nodejs utility script for cleaning up old files via a glob
To install use:
```shell
npm install node-util-fileclean --save
```
### Purpose
This script is designed to clean out old files.
For example "delete all old old files in ./reports directory that are older than 3 days"
The script finds all files using a supplied glob then orders using the [mtime or last modified time](https://nodejs.org/api/fs.html#fs_stat_time_values).
### Running the script
To run the script run the executable bin file provided, e.g:
```
./node_modules/.bin/node-util-fileclean --globs="./reports/*.html" --maxAgeDays=3 --dryRun=false
```
The above will delete any html files in the ./reports/ directory.
Note the flag: --dryRun=false, without this flag set to false the script will simply output the files to delete and the ones to keep to the console.
### Script Flags
The following is a list of the flags that the script supports.
`--globs="./reports/*.html,./output/**/*"`
> This flag is always required as it identifies all of the files in question.
> Globs are separated using commas, no spaces.
> This uses [globby](https://github.com/sindresorhus/globby) under the hood so please view documentation there to see all options.
`--maxAgeDays=1` `--maxAgeHours=1` `--maxAgeMins=1`
> The above is a list of the time flags that are possible. If you supply a time flag files older
> than the supplied value will be deleted. Only 1 is supported at a time.
`--maxFiles=100`
> This flag will set the total number of files that is kept.
`--dryRun=false`
> This flag is optional and will default to true. When set to true no files will be deleted so it can
> give you a chance to manually check the result. When set to false the files will be deleted.
> The script will always output a list of all the files it has found and sorted for your review.
> X prefix means delete, O prefix means keep.