2011年8月22日
摘要: 1.使用DirectoryInfo.MoveTo时,将目标文件夹一定要是不存在,不然报错。代码如下:View Code 1stringpath=@"c:\wtqCreate";2stringpathTxt=path+@"\my.txt";3stringwtqPath=@"c:\wtq";4stringwttqq=@"c:\wttq11";5DirectoryInfodi=newDirectoryInfo(path);6di.MoveTo(wttqq);2.将文件复制到另外一个目录中代码如下:View Code 1s 阅读全文
posted @ 2011-08-22 16:07 wtq 阅读(504) 评论(0) 推荐(0) 编辑
摘要: 1.Directory和DirectoryInfo这两个类都是对文件进行操作,但Directory是静态类,所以它的执行效率会更高一点。2.对文件操作。我们可以这样认为,Directory和directoryInfo都是一样的,只是表现形式不一样。 3.获取目录的文件名称或者是文件夹名称。代码如下;View Code 1stringpath=@"c:\wtqCreate";2stringpathTxt=path+@"\my.txt";3if(!Directory.Exists(path))4{56Directory.CreateDirectory(pat 阅读全文
posted @ 2011-08-22 15:08 wtq 阅读(278) 评论(0) 推荐(0) 编辑
摘要: 1.创建目录。创建目录和文件1stringpath=@"c:\wtqCreate";2stringpathTxt=path+@"\my.txt";3if(Directory.Exists(path))4{56Directory.Delete(path,true);7Directory.CreateDirectory(path);8using(StreamWritersw=File.CreateText(pathTxt))9{10sw.WriteLine("mynameiswtq");11sw.WriteLine("andwh 阅读全文
posted @ 2011-08-22 13:56 wtq 阅读(356) 评论(0) 推荐(0) 编辑
摘要: 1.思路,可使用directory和File文件相互结合。代码如下:View Code 1stringpath=Environment.CurrentDirectory;2stringpattern="*.txt";3string[]strFileName=Directory.GetFiles(path,pattern);4foreach(variteminstrFileName)5{6File.Delete(item);7Console.WriteLine("{0}文件被删除了",item);8}9Console.ReadLine();参考:direc 阅读全文
posted @ 2011-08-22 11:47 wtq 阅读(5891) 评论(0) 推荐(0) 编辑