Skip to content

Get list of all directories in a given directory with TypeScript

Advertisements
  
import * as fs from "fs"
import * as path from "path"
function getDirectories(directory: string): string[] {
    return fs.readdirSync(directory).filter(file => fs.statSync(path.join(directory, file)).isDirectory())
}
See also  TypeScript code snippet - How to take inputs and give outputs from a file in c?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.