Skip to main content
Deno 2 is finally here ๐ŸŽ‰๏ธ
Learn more

getFiles

Recursively get all files in a directory

getfiles ci GitHub release (latest by date) license Made by lencx

Usage

needs โ€“allow-read privilege

import getFiles, { exists, fileExt, trimPath, fmtFileSize } from "https://deno.land/x/getfiles/mod.ts";

// root path: './' or '.'
const files = getFiles('./');

// include files
const files2 = getFiles({
  root: './',
  include: ['examples'],
  hasInfo: true,
  // ignore: ['examples/include.ts'],
});

// exclude files
const files3 = getFiles({
  root: './',
  exclude: ['.git'],
  // ignore: ['*.ts'],
});

// if a file exists
const existFile = await exists('mod.ts');
console.log(existFile);

Methods

  • [fs] - getFiles: default export
  • [fs] - findFile
  • [utils] - exists
  • [utils] - fileExt: get file extensions
  • [utils] - trimPath: trim path
  • [utils] - fmtFileSize: converting file size in bytes to human readable string
  • [utils] - isStr

API

getFiles

Option Type Description Example
root string directory {root: โ€˜.โ€™}
include string[] include directory {root: โ€˜.โ€™, include: [โ€˜examplesโ€™]}
exclude string[] exclude directory {root: โ€˜.โ€™, exclude: [โ€˜.gitโ€™]}
ignore string[] ignore file rule {root: โ€˜.โ€™, ignore: [โ€˜*.mdโ€™, โ€˜**/*.tsโ€™, โ€˜examples/tree.tsโ€™]}
hasInfo boolean file details, default false {root: โ€˜.โ€™, hasInfo: true}

Examples