listDirContent

It takes a directory location and list every file or sub-directory in that directory.
The list consists of an array of strings where each element is the name of the file/sub-directory.
Parameter ListReturnsRejection Errors
  • dirLocation: string
  • tuple: Array (optional)
Promise<string || Array>
Related FunctionsFunction Signature
function listDirContent(dirLocation[, tuple]): Promise<string || Array>
1 2 3 4 5 import { listDirContent } from "puddy-m/lib/fileFunctions"; // Let's suppose that inside the foo directory, there is a file called bar.txt and fizz.txt // The function bellow will resolve an array ['bar.txt', 'fizz.txt'] listDirContent("foo").then((contents) => console.log(contents)); // prints ['bar.txt', 'fizz.txt']
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 import { listDirContent } from "puddy-m/lib/fileFunctions"; // Suppose the following tree structure in your file system // -foo // --bar.txt // --fiz.txt // -another // --dir // ---sample.txt listDirContent("foo", []) .then((tuple) => listDirContent("another/dir", tuple)) .then(([firstDirContent, secondDirContent]) => { console.log(firstDirContent); console.log(secondDirContent); }); // prints ['bar.txt', 'fizz.txt'] [sample.txt]