Ejemplo n.º 1
0
        /// <summary>
        /// CopyFileEx wrapper. Desktop only. Prefer FileManagement.CopyFile() as it will handle all supported platforms.
        /// </summary>
        /// <param name="overwrite">Overwrite an existing file if true.</param>
        public static void CopyFileEx(string source, string destination, bool overwrite = false)
        {
            bool cancel = false;

            if (!Direct.CopyFileExW(
                    lpExistingFileName: source,
                    lpNewFileName: destination,
                    lpProgressRoutine: null,
                    lpData: IntPtr.Zero,
                    pbCancel: ref cancel,
                    dwCopyFlags: overwrite ? 0 : CopyFileFlags.COPY_FILE_FAIL_IF_EXISTS))
            {
                throw ErrorHelper.GetIoExceptionForLastError(source);
            }
        }