码迷,mamicode.com
首页 > Windows程序 > 详细

C#文件夹和文件操作

时间:2014-12-10 16:09:11      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:ar   os   sp   for   文件   div   bs   ad   ef   

File.Exist(string   path)
//文件读写
FileStream fs=new FileStream(filename, FileMode.Create);
BinaryWriter bw=new BinaryWriter(fs);
bw.Write("OK");
bw.Flush();
bw.Close();
fs.Close();

if (!Directory.Exists(sPath))

{
     Directory.CreateDirectory(sPath);
}
 
C#遍历指定文件夹
DirectoryInfo TheFolder=new DirectoryInfo(folderFullName);
//遍历文件夹
foreach(DirectoryInfo NextFolder in TheFolder.GetDirectories())
this.listBox1.Items.Add(NextFolder.Name);
//遍历文件
foreach(FileInfo NextFile in TheFolder.GetFiles())
this.listBox2.Items.Add(NextFile.Name);
//遍历文件或者文件夹
 DirectoryInfo. GetFileSystemInfos():获取指定目录下(不包含子目录)的文件和子目录,返回类型为FileSystemInfo[],支持通配符查找;

C#文件夹和文件操作

标签:ar   os   sp   for   文件   div   bs   ad   ef   

原文地址:http://www.cnblogs.com/coolbear/p/4155364.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!