deno.land / std@0.126.0 / fs

import * as mod from "https://deno.land/std@0.126.0/fs/mod.ts";

Enums

EOL

EndOfLine character enum

Functions

_createWalkEntry

Create WalkEntry for the path asynchronously

_createWalkEntrySync

Create WalkEntry for the path synchronously

copy

Copy a file or directory. The directory can have contents. Like cp -r. Requires the --allow-read and --allow-write flag.

copySync

Copy a file or directory. The directory can have contents. Like cp -r. Requires the --allow-read and --allow-write flag.

detect

Detect the EOL character for string input. returns null if no newline

emptyDir

Ensures that a directory is empty. Deletes directory contents if the directory is not empty. If the directory does not exist, it is created. The directory itself is not deleted. Requires the --allow-read and --allow-write flag.

emptyDirSync

Ensures that a directory is empty. Deletes directory contents if the directory is not empty. If the directory does not exist, it is created. The directory itself is not deleted. Requires the --allow-read and --allow-write flag.

ensureDir

Ensures that the directory exists. If the directory structure does not exist, it is created. Like mkdir -p. Requires the --allow-read and --allow-write flag.

ensureDirSync

Ensures that the directory exists. If the directory structure does not exist, it is created. Like mkdir -p. Requires the --allow-read and --allow-write flag.

ensureFile

Ensures that the file exists. If the file that is requested to be created is in directories that do not exist. these directories are created. If the file already exists, it is NOTMODIFIED. Requires the --allow-read and --allow-write flag.

ensureFileSync

Ensures that the file exists. If the file that is requested to be created is in directories that do not exist, these directories are created. If the file already exists, it is NOT MODIFIED. Requires the --allow-read and --allow-write flag.

ensureLink

Ensures that the hard link exists. If the directory structure does not exist, it is created.

ensureLinkSync

Ensures that the hard link exists. If the directory structure does not exist, it is created.

ensureSymlink

Ensures that the link exists. If the directory structure does not exist, it is created.

ensureSymlinkSync

Ensures that the link exists. If the directory structure does not exist, it is created.

exists 👎 deprecated

Test whether or not the given path exists by checking with the file system

existsSync 👎 deprecated

Test whether or not the given path exists by checking with the file system

expandGlob

Expand the glob string from the specified root directory and yield each result as a WalkEntry object.

expandGlobSync

Synchronous version of expandGlob().

format

Format the file to the targeted EOL

move

Moves a file or directory

moveSync

Moves a file or directory synchronously

walk

Walks the file tree rooted at root, yielding each file or directory in the tree filtered according to the given options. The files are walked in lexical order, which makes the output deterministic but means that for very large directories walk() can be inefficient.

walkSync

Same as walk() but uses synchronous ops

fs

fs module is made to provide helpers to manipulate the filesystem.

Usage

Most of the following modules are exposed in mod.ts. This feature is currently unstable. To enable it use deno run --unstable.

emptyDir

Ensures that a directory is empty. Deletes directory contents if the directory is not empty. If the directory does not exist, it is created. The directory itself is not deleted.

import {
  emptyDir,
  emptyDirSync,
} from "https://deno.land/std@0.126.0/fs/mod.ts";

emptyDir("./foo"); // returns a promise
emptyDirSync("./foo"); // void

ensureDir

Ensures that the directory exists. If the directory structure does not exist, it is created. Like mkdir -p.

import {
  ensureDir,
  ensureDirSync,
} from "https://deno.land/std@0.126.0/fs/mod.ts";

ensureDir("./bar"); // returns a promise
ensureDirSync("./ensureDirSync"); // void

ensureFile

Ensures that the file exists. If the file that is requested to be created is in directories that do not exist, these directories are created. If the file already exists, it is NOT MODIFIED.

import {
  ensureFile,
  ensureFileSync,
} from "https://deno.land/std@0.126.0/fs/mod.ts";

ensureFile("./folder/targetFile.dat"); // returns promise
ensureFileSync("./folder/targetFile.dat"); // void

Ensures that the link exists. If the directory structure does not exist, it is created.

import {
  ensureSymlink,
  ensureSymlinkSync,
} from "https://deno.land/std@0.126.0/fs/mod.ts";

ensureSymlink("./folder/targetFile.dat", "./folder/targetFile.link.dat"); // returns promise
ensureSymlinkSync("./folder/targetFile.dat", "./folder/targetFile.link.dat"); // void

EOL

Detects and format the passed string for the targeted End Of Line character.

import {
  detect,
  EOL,
  format,
} from "https://deno.land/std@0.126.0/fs/mod.ts";

const CRLFinput = "deno\r\nis not\r\nnode";
const Mixedinput = "deno\nis not\r\nnode";
const LFinput = "deno\nis not\nnode";
const NoNLinput = "deno is not node";

detect(LFinput); // output EOL.LF
detect(CRLFinput); // output EOL.CRLF
detect(Mixedinput); // output EOL.CRLF
detect(NoNLinput); // output null

format(CRLFinput, EOL.LF); // output "deno\nis not\nnode"

exists

This function is now deprecated.

move

Moves a file or directory. Overwrites it if option provided.

import { move, moveSync } from "https://deno.land/std@0.126.0/fs/mod.ts";

move("./foo", "./bar"); // returns a promise
moveSync("./foo", "./bar"); // void
moveSync("./foo", "./existingFolder", { overwrite: true });
// Will overwrite existingFolder

copy

copy a file or directory. Overwrites it if option provided.

import { copy, copySync } from "https://deno.land/std@0.126.0/fs/copy.ts";

copy("./foo", "./bar"); // returns a promise
copySync("./foo", "./bar"); // void
copySync("./foo", "./existingFolder", { overwrite: true });
// Will overwrite existingFolder

walk

Iterate all files in a directory recursively.

import { walk, walkSync } from "https://deno.land/std@0.126.0/fs/mod.ts";

for (const entry of walkSync(".")) {
  console.log(entry.path);
}

// Async
async function printFilesNames() {
  for await (const entry of walk(".")) {
    console.log(entry.path);
  }
}

printFilesNames().then(() => console.log("Done!"));

expandGlob

Expand the glob string from the specified root directory and yield each result as a WalkEntry object.

import { expandGlob } from "https://deno.land/std@0.126.0/fs/mod.ts";

for await (const file of expandGlob("**/*.ts")) {
  console.log(file);
}

expandGlobSync

Synchronous version of expandGlob().

import { expandGlobSync } from "https://deno.land/std@0.126.0/fs/mod.ts";

for (const file of expandGlobSync("**/*.ts")) {
  console.log(file);
}
std
Deno standard library
GitHub Stars
2182
Go to latest

Version Info

Tagged at
4 months ago