Skip to content

Copy a file

The fs.copy function is used to copy a file from one location to another, the first argument is a string of the source file path, and the second argument is a string of the destination file path.

If the destination file exists, it will overwrite the file.

INFO

The fs.copy function is only used to copy a file or a symlink.

nv,

We have fs.link method to create a hard link to a file, and fs.symlink method to create a symbolic link to a file.

nv,

You also can use fs.readlink method to read the target of a symbolic link, this will return the string path of the link source.

nv,

And the fs.unlink method to remove a link.

Actually, the fs.unlink is a alias of fs.remove_file.