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命名空间

posted on 2012-09-29 17:41  计划  阅读(3780)  评论(0编辑  收藏  举报