/** * @brief The file guard class to manage the FILE pointer automatically. * file_guard object can close the FILE pointer automatically when his scope is exit. */ classfile_guard { public: /** * @brief Construct a new file guard object * * @param file the pointer of the FILE object */ explicitfile_guard(FILE *file);
/** * @brief Get the FILE pointer. * * @return FILE* */ FILE *getfd()const;
private: FILE *file_; };
/** * @brief Copy a file or symbolic link(shortcut on windows). * * @param srcpath the filepath of the source file or symbolic link to be copied * @param dstpath the filepath of the destination file or symbolic link to be copied to * @param attributes whether to copy the file attributes, default is false. * If true, means copy the file attributes, like the 'cp -p' command. * @return true if the file or symbolic link is copied successfully, false otherwise. * @note If the destination file or directory already exists, it will be overwritten. * @return false */ boolcopyfile(const filepath &srcpath, const filepath &dstpath, bool attributes = false);
// copy directory recursively /** * @brief Copy a directory recursively. * * @param srcdir the filepath of the source directory to be copied * @param dstdir the filepath of the destination directory to be copied to * @return true if the directory is copied successfully, false otherwise. * @note If the destination directory already exists, it will be overwritten. */ boolcopydir(const filepath &srcdir, const filepath &dstdir);