Пример #1
0
 public static extern bool SHFileOperation(ref Shfileopstruct lpFileOp);
Пример #2
0
        /// <summary>
        /// 删除文件或者文件夹到回收站(Win32API实现)
        /// </summary>
        /// <param name="path">路径</param>
        /// <param name="isMoveToRecycleBin">是否移动到回收站,true移到回收站,false直接删除</param>
        /// <returns>删除成功返回true</returns>
        public static bool DeleteToRecycleBin(string path, bool isMoveToRecycleBin)
        {
            Shfileopstruct lpFileOp = new Shfileopstruct
            {
                WFunc = NativeConstants.FO_DELETE,
                PFrom = path + "\0",
                FFlags = NativeConstants.FOF_NOCONFIRMATION | NativeConstants.FOF_NOERRORUI | NativeConstants.FOF_SILENT
            };
            if (!isMoveToRecycleBin)
            {
                lpFileOp.FFlags &= ~NativeConstants.FOF_ALLOWUNDO;
            }
            lpFileOp.FAnyOperationsAborted = false;

            return NativeMethods.SHFileOperation(ref lpFileOp);
        }