-
Notifications
You must be signed in to change notification settings - Fork 280
/
Copy pathsymlinks.ts
30 lines (25 loc) · 1.01 KB
/
symlinks.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/**
* @title Creating & resolving symlinks
* @difficulty beginner
* @tags cli
* @run -W -R <url>
* @resource {https://docs.deno.com/api/deno/~/Deno.writeTextFile} Doc: Deno.writeTextFile
* @resource {https://docs.deno.com/api/deno/~/Deno.symlink} Doc: Deno.symlink
* @group File System
*
* Creating and resolving symlink is a common task. Deno has a number of
* functions for this task.
*/
// First we will create a text file to link to.
await Deno.writeTextFile("example.txt", "hello from symlink!");
// Now we can create a soft link to the file
await Deno.symlink("example.txt", "link");
// To resolve the path of a symlink, we can use Deno.realPath
console.log(await Deno.realPath("link"));
// Symlinks are automatically resolved, so we can just read
// them like text files
console.log(await Deno.readTextFile("link"));
// In certain cases, soft links don't work. In this case we
// can choose to make "hard links".
await Deno.link("example.txt", "hardlink");
console.log(await Deno.readTextFile("hardlink"));