To use the emptydir
function from the fs-extra
library in TypeScript, first you need to install the package via npm:
28 chars2 lines
Then, in your TypeScript file, import the function as follows:
index.ts37 chars2 lines
You can then use the emptyDir
function to delete the contents of a directory. Here's an example:
index.ts202 chars7 lines
The emptyDir
function returns a Promise that resolves once the directory has been emptied or rejects if an error occurs.
Note that if the directory does not exist, the emptyDir
function will not throw an error but will simply resolve without doing anything. If you need to create the directory if it does not exist, you can use the mkdirs
function from fs-extra
to create it first:
index.ts314 chars10 lines
This will ensure that the directory exists before attempting to delete its contents.
gistlibby LogSnag