C#文件操作語句:
//檢查文件是否存在 File.Exists(@"c:\my folder\filename"); try { File.Delete(@"c:\jihua.cnblogs.com.txt"); } catch { MessageBox.Show("刪除失敗", "jihua.cnblogs.com"); } try { File.Create(@"c:\jihua.cnblogs.com.txt"); } catch { MessageBox.Show("創建失敗", "jihua.cnblogs.com"); } try { File.Move(@"c:\jihua.cnblogs.com.txt", @"c:\new.jihua.cnblogs.com.txt"); } catch { MessageBox.Show("移動失敗", "jihua.cnblogs.com"); }
C#文件夾操作語句:
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"); }
記得引用System.IO命名空間
