Class

FSDir

FSDir(path)

Contains all methods for work with directories
Constructor

# new FSDir(path)

Parameters:
Name Type Description
path string valid filesystem path string

View Source fs-dir.class.ts, line 24

Classes

FSDir

Members

# fspath

Return FSPath function for current path. Can be used to countinue joining path segments to subdirs or files.

View Source fs-dir.class.ts, line 39

FSPathType

# fspath

Return FSPath function for current path. Can be used to countinue joining path segments to subdirs or files.

View Source fs-dir.class.ts, line 227

# name

Directory name

View Source fs-dir.class.ts, line 34

string

# name

Directory name

View Source fs-dir.class.ts, line 220

Methods

# async copyTo(targetDir)

Recursively copy current directory to the target dir
Parameters:
Name Type Description
targetDir Directory in which will be copy current

View Source fs-dir.class.ts, line 178

# dirents() → {FSAsyncIterable.<Dirent>}

Return async iterator which iterates all dirents in dir. Chaining map, filter and forEach operators available. toArray operator can be used for resulting chain to array.

View Source fs-dir.class.ts, line 47

FSAsyncIterable.<Dirent>

# files() → {FSAsyncIterable}

Return async iterator which iterates all files in dir. Chaining map, filter and forEach operators available. toArray operator can be used for resulting chain to array.

View Source fs-dir.class.ts, line 55

# async isExists() → {Promise.<boolean>}

Checks is dir exits

View Source fs-dir.class.ts, line 121

Promise.<boolean>

# async mkdir(recursive)

Asynchronously creates a directory.
Parameters:
Name Type Default Description
recursive false if recursive is true, the first directory path created

View Source fs-dir.class.ts, line 108

# async moveTo(targetDir)

Moves diretory to the new path
Parameters:
Name Type Description
targetDir target directory

View Source fs-dir.class.ts, line 195

moved direrectory

# async rimraf()

Removes directory with all content

View Source fs-dir.class.ts, line 163

# async rmdir()

delete a directory

View Source fs-dir.class.ts, line 95

# subdirs(recursive) → {FSAsyncIterable}

Return async iterator wich iterates each subdirs. Chaining map, filter and forEach operators available. toArray operator can be used for resulting chain to array.
Parameters:
Name Type Default Description
recursive false if true returns each subdir of any deep

View Source fs-dir.class.ts, line 82

Example

Extratct all module names and versions from node_modules

const { cwd } = require('fstb');
cwd
 .node_modules()
 .asDir()
 .subdirs(true)
 .map(async dir => dir.fspath['package.json']().asFile())
 .filter(async package_json => await package_json.isReadable())
 .map(async package_json => await package_json.read.json())
 .forEach(async content => console.log(`${content.name}@${content.version}`));

# async totalSize()

Compute total size of this directory.

View Source fs-dir.class.ts, line 146

Example

Total size of node_modules

  console.log(
'Total size of node_modules is ' +
  Math.floor(
    (await cwd
      .node_modules()
      .asDir()
      .totalSize()) /
      1024 /
      1024
  ) +
  ' MBytes'
);