Copy a file or directory. The directory can have contents. Like {\ttfamily cp -\/r}.


\begin{DoxyItemize}
\item {\ttfamily src} {\ttfamily $<$String$>$}
\item {\ttfamily dest} {\ttfamily $<$String$>$}
\item {\ttfamily options} {\ttfamily $<$Object$>$}
\begin{DoxyItemize}
\item {\ttfamily overwrite} {\ttfamily $<$boolean$>$}\+: overwrite existing file or directory, default is {\ttfamily true}. {\itshape Note that the copy operation will silently fail if you set this to {\ttfamily false} and the destination exists.} Use the {\ttfamily error\+On\+Exist} option to change this behavior.
\item {\ttfamily error\+On\+Exist} {\ttfamily $<$boolean$>$}\+: when {\ttfamily overwrite} is {\ttfamily false} and the destination exists, throw an error. Default is {\ttfamily false}.
\item {\ttfamily dereference} {\ttfamily $<$boolean$>$}\+: dereference symlinks, default is {\ttfamily false}.
\item {\ttfamily preserve\+Timestamps} {\ttfamily $<$boolean$>$}\+: will set last modification and access times to the ones of the original source files, default is {\ttfamily false}.
\item {\ttfamily filter} {\ttfamily $<$Function$>$}\+: Function to filter copied files. Return {\ttfamily true} to include, {\ttfamily false} to exclude. This can also be a Reg\+Exp, however this is deprecated (See \href{https://github.com/jprichardson/node-fs-extra/issues/239}{\texttt{ issue \#239}} for background).
\end{DoxyItemize}
\item {\ttfamily callback} {\ttfamily $<$Function$>$}
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_fs_extra_docs_copy_autotoc_md10993}{}\doxysection{Example\+:}\label{md_sfcode_node_modules_fs_extra_docs_copy_autotoc_md10993}

\begin{DoxyCode}{0}
\DoxyCodeLine{const fs = require('fs-\/extra')}
\DoxyCodeLine{}
\DoxyCodeLine{fs.copy('/tmp/myfile', '/tmp/mynewfile', err => \{}
\DoxyCodeLine{  if (err) return console.error(err)}
\DoxyCodeLine{}
\DoxyCodeLine{  console.log('success!')}
\DoxyCodeLine{\}) // copies file}
\DoxyCodeLine{}
\DoxyCodeLine{fs.copy('/tmp/mydir', '/tmp/mynewdir', err => \{}
\DoxyCodeLine{  if (err) return console.error(err)}
\DoxyCodeLine{}
\DoxyCodeLine{  console.log('success!')}
\DoxyCodeLine{\}) // copies directory, even if it has subdirectories or files}
\DoxyCodeLine{}
\DoxyCodeLine{// Promise usage:}
\DoxyCodeLine{fs.copy('/tmp/myfile', '/tmp/mynewfile')}
\DoxyCodeLine{.then(() => \{}
\DoxyCodeLine{  console.log('success!')}
\DoxyCodeLine{\})}
\DoxyCodeLine{.catch(err => \{}
\DoxyCodeLine{  console.error(err)}
\DoxyCodeLine{\}) }

\end{DoxyCode}


{\bfseries{Using filter function}}


\begin{DoxyCode}{0}
\DoxyCodeLine{const fs = require('fs-\/extra')}
\DoxyCodeLine{}
\DoxyCodeLine{const filterFunc = (src, dest) => \{}
\DoxyCodeLine{  // your logic here}
\DoxyCodeLine{  // it will be copied if return true}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{fs.copy('/tmp/mydir', '/tmp/mynewdir', \{ filter: filterFunc \}, err => \{}
\DoxyCodeLine{  if (err) return console.error(err)}
\DoxyCodeLine{}
\DoxyCodeLine{  console.log('success!')}
\DoxyCodeLine{\}) }

\end{DoxyCode}
 