Beispiel #1
0
        internal static void Recycle(string path)
        {
            var shf = new Shell32.SHFILEOPSTRUCT();

            shf.wFunc  = Shell32.FO_Func.FO_DELETE;
            shf.fFlags = Shell32.FOF_ALLOWUNDO | Shell32.FOF_NO_UI;
            shf.pFrom  = Marshal.StringToHGlobalUni(path + '\0');

            var ret = Shell32.SHFileOperation(ref shf);

            if (ret != 0)
            {
                throw new Exception("Error #" + ret);
            }
        }
Beispiel #2
0
        public static bool CopyFiles(IEnumerable <string> items, string destination)
        {
            try
            {
                var fs = new Shell32.SHFILEOPSTRUCT
                {
                    wFunc = Shell32.FileOperationType.FO_COPY,
                    pFrom = string.Join("\0", items.ToArray()) + '\0' + '\0',
                    pTo   = destination + '\0' + '\0'
                };
                int result = Shell32.SHFileOperation(ref fs);

                return(result == 0);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Beispiel #3
0
        public static bool DeleteFileOrFolder(string destination)
        {
            try
            {
                var fs = new Shell32.SHFILEOPSTRUCT
                {
                    wFunc  = Shell32.FileOperationType.FO_DELETE,
                    pFrom  = destination + '\0' + '\0',
                    fFlags = Shell32.FileOperationFlags.FOF_NOCONFIRMATION |
                             Shell32.FileOperationFlags.FOF_NOERRORUI |
                             Shell32.FileOperationFlags.FOF_SILENT
                };

                int result = Shell32.SHFileOperation(ref fs);
                return(result == 0);
            }
            catch (Exception)
            {
                return(false);
            }
        }