internal static int CopyFile(String src, String dst, bool failIfExists) { uint copyFlags = failIfExists ? (uint)Interop.mincore.FileOperations.COPY_FILE_FAIL_IF_EXISTS : 0; Interop.mincore.COPYFILE2_EXTENDED_PARAMETERS parameters = new Interop.mincore.COPYFILE2_EXTENDED_PARAMETERS() { dwSize = (uint)Marshal.SizeOf <Interop.mincore.COPYFILE2_EXTENDED_PARAMETERS>(), dwCopyFlags = copyFlags }; int hr = Interop.mincore.CopyFile2(src, dst, ref parameters); return(Win32Marshal.TryMakeWin32ErrorCodeFromHR(hr)); }