In the index.js
file of the 04-copy-directory
folder, implement the copyDir
function, which copies the contents of the files folder to the files-copy
folder.
- The use of any third-party modules is prohibited.
- Each task must be executed in the root directory using the command
node <task folder name>
. - The use of synchronous functions from the fs module, such as
fs.statSync(path[, options])
,fs.readFileSync(path[, options])
, and others found in the synchronous API section, is prohibited.
- After the function execution terminates, a
files-copy
folder is created, the contents of which are an exact copy of the originalfiles
folder. - When files are added/removed/modified in the
files
folder and thenode 04-copy-directory
is rerun, the contents of thefiles-copy
folder are updated. - The use of
fsPromises.cp()
is prohibited.
- Learn to copy files and directories.
Steps to complete the task:
- Import all required modules.
- Create the
files-copy
folder if it does not exist yet. - Read the contents of the
files
folder. - Copy files from the
files
folder to thefiles-copy
folder.
Pay attention to the recursive
option that can be passed to fsPromises/mkdir
. With its help, you can avoid errors in cases where the directory already exists.