fs.unlink
but accepts regex, works with Promise
and callback
approach.
Why accepts regex? simply glob
core using minimatch
that use regex.
npm install regex-unlink
The usage was so simple and similar with fs.unlink
.
// delete files with `.txt` extension using callback approach
unlink("**/**.txt", (err) => {
if (err) {
console.log(err);
return;
}
console.log("Delete all .txt files successful!");
});
// you can specify path without regex
unlink("./text.txt", (err) => {
if (err) {
console.log(err);
return;
}
console.log("Delete all .txt files successful!");
});
// delete files with `.txt` extension using asynchronous approach
(async () => {
await asyncUnlink("**/**.txt", (err) => {
if (err) {
console.log(err);
}
console.log("Delete all .txt files successful!");
});
})();
examples here.
declaration files here.
-
options:
const options: globOptions;
options binding for glob -
unlink:
function unlink(path: string, callback?: Function): void;
unlink usingcallback
, equivalent offs.unlink
-
asyncUnlink:
function asyncUnlink(path: string): Promise<void>;
unlink usingPromise
, equivalent offs.promises.unlink
regex-unlink
using the MIT License