A tiny (241B to 339B) utility to copy items recursively
This is a Promise
-based, cross-platform utility that recursively copy files and directories.
Notice: Node v16.7.0 added an experimental
fs.cp
andfs.cpSync
.
$ npm install --save @tatchi/dcopy
There are two "versions" of dcopy
available:
This is the primary/default mode. It makes use of async
/await
and util.promisify
.
This is the opt-in mode, ideal for scenarios where async
usage cannot be supported.
In order to use it, simply make the following changes:
-import { dcopy } from 'dcopy';
+import { dcopy } from 'dcopy/sync';
import { dcopy } from "dcopy";
// Async/await
try {
await dcopy("./foobar", "./foobar_copy");
} catch (err) {
//
}
// Promise
dcopy("./foobar", "./foobar_copy")
.then(() => {
//
})
.catch((err) => {
//
});
// Sync
import { dcopy } from "dcopy/sync";
dcopy("./foobar", "./foobar_copy");
Returns: Promise<void>
Returns a Promise that resolves when all the files/folders have been copied to the destination.
Important:
Thesync
andasync
versions share the same API.
The only difference is thatsync
is not Promise-based.
Type: String
The filepath to copy from โ may be a file or a directory.
Type: String
The filepath to copy to.
This library is heavily inspired from and reuses lots of lukeed's work. Thanks for his amazing work ๐