Delete all files and folders in a target directory, according to a threshHold file size.
npm install clean-sweep -g
clean-sweep <path/to/directory> -v -t <bytes>
# OR
csw <path/to/directory> -v -t <bytes>
- The first argument is the path to the directory in which the operation would be performed, and is required!
- The remaining are optional
-v: prints out the operation of the sweep function to console if specified -t: specifies the threshold. Threshold here is the file size(in bytes), in which with, files with sizes below this threshold, are deleted
clean-sweep ./music
clean-sweep ./music -v
clean-sweep ./music -t 200
# OR
csw ./music
csw ./music -v
csw ./music -t 200
npm install clean-sweep --save
const cleanSweep = require("clean-sweep");
const fileDirectory = "<replace file directory here>";
try {
cleanSweep.sweepSync(fileDirectory, {
/* specify if operation info should be printed to console, defaults to false */
verbose: true,
/* all files with size(in byte) below this thresh hold are deleted, defaults to 0 */
threshHold: 200
});
} catch (err) {
if (err.code == "ENOENT") {
console.error("Directory does not exist");
} else {
console.error(err.message);
}
}
const cleanSweep = require("clean-sweep").promises;
const fileDirectory = "<replace file directory here>";
(async function () {
try {
await cleanSweep.sweep(fileDirectory, {
/* specify if operation info should be printed to console, defaults to false */
verbose: true,
/* all files with size(in byte) below this thresh hold are deleted, defaults to 0 */
threshHold: 200
});
} catch (err) {
if (err.code == "ENOENT") {
console.error("Directory does not exist");
} else {
console.error(err.message);
}
}
})();