自由、探索、求知、创新,创造自我

博客园 首页 新随笔 联系 订阅 管理
 1public class FileDelete
 2    {
 3        private  const  int  FO_DELETE  =  0x3;  
 4        private  const  ushort  FOF_NOCONFIRMATION  =  0x10;  
 5        private  const  ushort  FOF_ALLOWUNDO  =  0x40;  
 6 
 7        [DllImport("shell32.dll",  SetLastError=true,  CharSet=CharSet.Unicode)]  
 8        private  static  extern  int  SHFileOperation([In,Out]  _SHFILEOPSTRUCT  str);  
 9 
10        [StructLayout(LayoutKind.Sequential,  CharSet=CharSet.Unicode)]  
11            private  class  _SHFILEOPSTRUCT  
12        {  
13            public  IntPtr  hwnd;  
14            public  UInt32  wFunc;  
15            public  string  pFrom;  
16            public  string  pTo;  
17            public  UInt16  fFlags;  
18            public  Int32  fAnyOperationsAborted;  
19            public  IntPtr  hNameMappings;  
20            public  string  lpszProgressTitle;  
21        }
 
22        public  static  bool  Delete(string  path)  
23        {  
24            _SHFILEOPSTRUCT  pm  =  new  _SHFILEOPSTRUCT();  
25            pm.wFunc  =  FO_DELETE;  
26            pm.pFrom  =  path  +  '\0';  
27            pm.pTo  =  null;  
28            pm.fFlags  =  FOF_ALLOWUNDO    |  FOF_NOCONFIRMATION;  
29            int i =  SHFileOperation(pm);  
30            if(i == 0)
31                return true;
32            return false;
33        }
  
34
35    }
posted on 2007-03-05 11:58  寂莫渔夫  阅读(295)  评论(0编辑  收藏  举报