1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
using System;
using System.IO;
using System.Runtime.InteropServices;
public class Files{
public enum FO : int
{
FO_COPY = 2,
FO_DELETE = 3,
FO_MOVE = 1,
FO_RENAME=4,
FOF_CONFIRMMOUSE = 0x2,
FOF_ALLOWUNDO = 0x40,
FOF_FILESONLY = 0x80,
FOF_MULTIDESTFILES = 0x1,
FOF_NOCONFIRMATION = 0x10, //Don't prompt the user.;
FOF_NOCONFIRMMKDIR = 0x200,
FOF_NO_CONNECTED_ELEMENTS = 0x1000,
FOF_NOCOPYSECURITYATTRIBS = 0x800,
FOF_NOERRORUI = 0x0400,
FOF_RENAMEONCOLLISION = 0x8,
FOF_SILENT = 0x4,
FOF_SIMPLEPROGRESS = 0x100,
FOF_WANTMAPPINGHANDLE = 0x20,
FOF_WANTNUKEWARNING = 0x2000,
FOF_NORECURSION = 0x1000
}
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto, Pack=1)]
public struct SHFILEOPSTRUCT
{
public IntPtr hwnd;
public int wFunc;
public string pFrom;
public string pTo;
public short fFlags;
public bool fAnyOperationsAborted;
public IntPtr hNameMappings;
public string lpszProgressTitle;
}
[DllImport("shell32.dll", CharSet=CharSet.Auto)]
public static extern int SHFileOperation(ref SHFILEOPSTRUCT FileOp);
public void CopyFile(string pFrom, string pTo)
{
long retval;
SHFILEOPSTRUCT shf = new SHFILEOPSTRUCT();
shf.wFunc = (int)FO.FO_COPY;
shf.fFlags = (int)FO.FOF_NOCONFIRMMKDIR
| (int)FO.FOF_WANTMAPPINGHANDLE;
shf.pFrom = pFrom+'\0'+'\0';
shf.pTo = pTo + '\0' + '\0';
shf.fAnyOperationsAborted = true;
retval = SHFileOperation(ref shf);
Console.WriteLine(retval);
}
} |
Partager