####文件操作
1 //检查文件是否存在 2 File.Exists(@"c:my folderfilename"); 3 try { File.Delete(@"c:jihua.cnblogs.com.txt"); } 4 catch 5 { 6 MessageBox.Show("删除失败", "jihua.cnblogs.com"); 7 } 8 try { File.Create(@"c:jihua.cnblogs.com.txt"); } 9 catch 10 { 11 MessageBox.Show("创建失败", "jihua.cnblogs.com"); 12 } 13 try { File.Move(@"c:jihua.cnblogs.com.txt", @"c: ew.jihua.cnblogs.com.txt"); } 14 catch 15 { 16 MessageBox.Show("移动失败", "jihua.cnblogs.com"); 17 } 18 //打开文件 19 if (Msg.AskQuestion("是否打开文件?")) 20 { 21 System.Diagnostics.Process.Start(filename); 22 } 23
####文件夹操作
bool exists = Directory.Exists(@"c:my folder");//检查文件夹是否存 try { Directory.Delete(@"c:my folder"); } catch { MessageBox.Show("删除失败", "jihua.cnblogs.com"); } try { Directory.CreateDirectory(@"c:my folder"); } catch { MessageBox.Show("创建失败","jihua.cnblogs.com"); } try { Directory.Move(@"c:my folder",@"d:folder"); } catch { MessageBox.Show("移动失败", "jihua.cnblogs.com"); }