# # #文件操作
1 //Check if the file exists2File.exists (@"C:\My Folder\filename");3Try{File.delete (@"C:\jihua.cnblogs.com.txt"); }4Catch5 {6MessageBox.Show ("Delete Failed","jihua.cnblogs.com");7 }8Try{File.create (@"C:\jihua.cnblogs.com.txt"); }9 CatchTen { OneMessageBox.Show ("creation failed","jihua.cnblogs.com"); A } -Try{File.move (@"C:\jihua.cnblogs.com.txt",@"C:\new.jihua.cnblogs.com.txt"); } -Catch the { -MessageBox.Show ("Move failed","jihua.cnblogs.com"); - } -//Open File +if(Msg.askquestion ("do you want to open the file? ")) - { + System.Diagnostics.Process.Start (filename); A } at
# # #文件夹操作
BOOLexists = Directory.Exists (@"C:\My Folder");//Check if the folder is storedTry{Directory.delete (@"C:\My Folder"); } Catch{MessageBox.Show ("Delete Failed","jihua.cnblogs.com"); } Try{Directory.CreateDirectory (@"C:\My Folder"); } Catch{MessageBox.Show ("creation failed","jihua.cnblogs.com"); } Try{Directory.move (@"C:\My Folder",@"D:\Folder"); } Catch{MessageBox.Show ("Move failed","jihua.cnblogs.com"); }
C # File operations