index.tsx362 chars14 lines
The emptyDirSync
function from the fs-extra
library takes in a directory path as its parameter and deletes all contents of the directory. The function works synchronously and will wait until all files have been deleted before it returns.
In the example code above, we first import the fs-extra
library and define a directoryPath
string that specifies the path to the directory we want to empty. We then call emptyDirSync
with the directoryPath
parameter and log a success message to the console. If an error occurs, we catch it and log the error message to the console.
gistlibby LogSnag