Top / JUNK / SHFileOperation

SHFileOperation のサンプル

API

using System;
using System.Runtime.InteropServices;

static class NativeMethods {
    public enum FileFuncFlags : uint {
        FO_MOVE = 0x1,
        FO_COPY = 0x2,
        FO_DELETE = 0x3,
        FO_RENAME = 0x4
    }

    [Flags]
    public enum FILEOP_FLAGS : ushort {
        FOF_MULTIDESTFILES = 0x1,
        FOF_CONFIRMMOUSE = 0x2,
        FOF_SILENT = 0x4,
        FOF_RENAMEONCOLLISION = 0x8,
        FOF_NOCONFIRMATION = 0x10,
        FOF_WANTMAPPINGHANDLE = 0x20,
        FOF_ALLOWUNDO = 0x40,
        FOF_FILESONLY = 0x80,
        FOF_SIMPLEPROGRESS = 0x100,
        FOF_NOCONFIRMMKDIR = 0x200,
        FOF_NOERRORUI = 0x400,
        FOF_NOCOPYSECURITYATTRIBS = 0x800,
        FOF_NORECURSION = 0x1000,
        FOF_NO_CONNECTED_ELEMENTS = 0x2000,
        FOF_WANTNUKEWARNING = 0x4000,
        FOF_NORECURSEREPARSE = 0x8000
    }

    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
    public struct SHFILEOPSTRUCT {
        public IntPtr hwnd;
        public FileFuncFlags wFunc;
        [MarshalAs(UnmanagedType.LPTStr)]
        public string pFrom;
        [MarshalAs(UnmanagedType.LPTStr)]
        public string pTo;
        public FILEOP_FLAGS fFlags;
        [MarshalAs(UnmanagedType.Bool)]
        public bool fAnyOperationsAborted;
        public IntPtr hNameMappings;
        [MarshalAs(UnmanagedType.LPTStr)]
        public string lpszProgressTitle;
    }

    [DllImport("shell32.dll", CharSet = CharSet.Auto)]
    public static extern int SHFileOperation(ref SHFILEOPSTRUCT lpFileOp);

}

実行

    using System;
    using System.Diagnostics;

    static class Program
    {
        [STAThread]
        static void Main() {
            var fileOp = new NativeMethods.SHFILEOPSTRUCT {
                wFunc = NativeMethods.FileFuncFlags.FO_COPY,
                pFrom = "C:\\work\\*.*\0\0",
                pTo = "C:\\Work2\0\0",
                fFlags = NativeMethods.FILEOP_FLAGS.FOF_NOCONFIRMATION | NativeMethods.FILEOP_FLAGS.FOF_NOCONFIRMMKDIR,
                fAnyOperationsAborted = true,
                hNameMappings = IntPtr.Zero,
            };
            NativeMethods.SHFileOperation(ref fileOp);
            Debug.Print("{0}", fileOp.fAnyOperationsAborted);
        }
    }



トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   最終更新のRSS
Last-modified: 2019-09-20 (金) 14:32:19 (293d)