Add recursive directory copying to the Node.js fs
module.
Recursively copying a directory is a common task and this currently requires using a third-party library. One of the goals of the Tooling Working Group is to add recursive functionality to the fs
module. For example, we recently added an rm
command that allows you to recursively remove a directory.
Add a new method to the fs
module named cp
. This method will work similarly to the UNIX cp
command and will initially provide a recursive
option. We may add some additional options from the cp
command if they make sense to include in Node.js.
We could do nothing and continue to leave this functionality up to third-party libraries. Some drawbacks to this include having to require a third-party library as well as having to choose from the available third-party libraries.
recursive
option to the fs.copyFile
commandWe initially implemented recursive directory removal in a simiar way by adding it to the fs.rmdir
command. We ended up moving this into a new fs.rm
method since the UNIX version of rmdir
does not delete files so this API was a bit confusing. We had to deprecate recursive rmdir
in Node 15, however it might never be feasible to remove it entirely. We would like to avoid making the same mistakes again.
We need to decide if we want to copy a recursive copy implementation from one of the existing libraries or if we'd rather make our own.
There are a number of third-party libraries that include this functioanlity, including:
cp
command should we include?cp
behaves differently if the source path ends with a /
, is that something we want?cp -n
doesn't overwrite an existing targetcp -f
will delete and recreate files it can't openor
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Syncing