using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
namespace KachelearnemChurjawenikall;
static void Main(string[] args)
var sourceFile = @"F:\temp\1";
var targetFile = @"F:\temp\2";
if (!File.Exists(sourceFile))
var buffer = new byte[1024 * 1024];
for (int i = 0; i < 1000; i++)
Random.Shared.NextBytes(buffer);
File.AppendAllBytes(sourceFile, buffer);
string[] sourceFiles = [sourceFile];
string[] targetFiles = [targetFile];
SHFILEOPSTRUCT pm = new SHFILEOPSTRUCT();
pm.wFunc = wFunc.FO_COPY;
pm.lpszProgressTitle = "复制文件";
pm.pFrom = string.Join(FILE_SPLITER, sourceFiles) + $"{FILE_SPLITER}{FILE_SPLITER}";
pm.pTo = string.Join(FILE_SPLITER, targetFiles) + $"{FILE_SPLITER}{FILE_SPLITER}";
pm.fFlags = FILEOP_FLAGS.FOF_NOCONFIRMATION | FILEOP_FLAGS.FOF_MULTIDESTFILES | FILEOP_FLAGS.FOF_ALLOWUNDO;
/// <param name="lpFileOp"></param>
[DllImport("shell32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
private static extern int SHFileOperation(SHFILEOPSTRUCT lpFileOp);
private const string FILE_SPLITER = "\0";
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
private class SHFILEOPSTRUCT
public FILEOP_FLAGS fFlags;
public bool fAnyOperationsAborted;
public IntPtr hNameMappings;
public string lpszProgressTitle;
/// 参见:http://msdn.microsoft.com/zh-cn/library/bb759795(v=vs.85).aspx
private enum FILEOP_FLAGS
///The pTo member specifies multiple destination files (one for each source file) rather than one directory where all source files are to be deposited.
FOF_MULTIDESTFILES = 0x1,
///Do not display a progress dialog box.
///Give the file being operated on a new name in a move, copy, or rename operation if a file with the target name already exists.
FOF_RENAMEONCOLLISION = 0x8,
///Respond with "Yes to All" for any dialog box that is displayed.
FOF_NOCONFIRMATION = 0x10,
///填充 hNameMappings 字段,必须使用 SHFreeNameMappings 释放
///If FOF_RENAMEONCOLLISION is specified and any files were renamed, assign a name mapping object containing their old and new names to the hNameMappings member.
FOF_WANTMAPPINGHANDLE = 0x20,
///Preserve Undo information, if possible. If pFrom does not contain fully qualified path and file names, this flag is ignored.
///Perform the operation on files only if a wildcard file name (*.*) is specified.
///Display a progress dialog box but do not show the file names.
FOF_SIMPLEPROGRESS = 0x100,
///Do not confirm the creation of a new directory if the operation requires one to be created.
FOF_NOCONFIRMMKDIR = 0x200,
///Do not display a user interface if an error occurs.
///Do not copy the security attributes of the file.
FOF_NOCOPYSECURITYATTRIBS = 0x800,
///Only operate in the local directory. Don't operate recursively into subdirectories.
FOF_NORECURSION = 0x1000,
///Do not move connected files as a group. Only move the specified files.
FOF_NO_CONNECTED_ELEMENTS = 0x2000,
///Send a warning if a file is being destroyed during a delete operation rather than recycled. This flag partially overrides FOF_NOCONFIRMATION.
FOF_WANTNUKEWARNING = 0x4000,
///Treat reparse points as objects, not containers.
FOF_NORECURSEREPARSE = 0x8000,