To use the opendir function from the fs-extra library in TypeScript, you first need to install the library by running the following command:
index.ts28 chars2 lines
After installing the library, you can import the opendir function from the fs-extra library and use it in your TypeScript code as follows:
index.ts185 chars9 linesIn the above code:
opendir function from the fs-extra library using ES6 import statements.async function named listFiles that takes a path parameter.listFiles function, we call the opendir function with the path parameter and await the returned Dir object.Dirent objects in the directory using a for await...of loop and log each file or folder name to the console.Note that using opendir requires Node.js version 12 or later.
gistlibby LogSnag