C#-文件目录-文件目录操作
来源:互联网 发布:mac有好用的看图软件吗 编辑:程序博客网 时间:2024/04/30 20:31
找子目录可以这样做:
递归实现查找目录下的所有子目录和文件
引用:http://topic.csdn.net/t/20050630/18/4115459.html
using System;using System.IO;class Test { public static void Main() { try { // Only get subdirectories that begin with the letter "p. " string[] dirs = Directory.GetDirectories(@ "c:\ ", "p* "); Console.WriteLine( "The number of directories starting with p is {0}. ", dirs.Length); foreach (string dir in dirs) { Console.WriteLine(dir); } } catch (Exception e) { Console.WriteLine( "The process failed: {0} ", e.ToString()); } }}
取本地目录内的文件名
private void showDirFiles(string strPath){try{if (!Directory.Exists(strPath)){//目录不存在,创建目录Directory.CreateDirectory(strPath);}DirectoryInfo mydir=new DirectoryInfo(strPath);FileInfo [] files=mydir.GetFiles();this.listBoxC.Items.Clear();//清楚listbox中现有项目for(int i=0;i <files.Length;i++){this.listBoxC.Items.Add(files[i].ToString());}}catch(Exception ex){MessageBox.Show(ex.Message);}}
递归实现查找目录下的所有子目录和文件
public void FindFile(string dir) //参数为指定的目录{ //在指定目录及子目录下查找文件,在listBox1中列出子目录及文件DirectoryInfo Dir=new DirectoryInfo(dir);try{ foreach(DirectoryInfo d in Dir.GetDirectories()) //查找子目录 {FindFile(Dir+d.ToString()+ "\\ ");listBox1.Items.Add(Dir+d.ToString()+ "\\ "); //listBox1中填加目录名} foreach(FileInfo f in Dir.GetFiles( "*.* ")) //查找文件{listBox1.Items.Add(Dir+f.ToString()); //listBox1中填加文件名}}catch(Exception e){MessageBox.Show(e.Message);}}调用private void button1_Click(object sender, System.EventArgs e){string currentdir= "F:\\myprogram\\C#\\FileSearch "; //搜索的目录if(currentdir[currentdir.Length-1]!= '\\ ') //非根目录currentdir+= "\\ "; FindFile(currentdir); //调用查找文件函数}加上 using System.IO;
引用:http://topic.csdn.net/t/20050630/18/4115459.html
- C#-文件目录-文件目录操作
- C#.NET 文件目录操作类
- C++builder 文件及目录的操作
- C#--文件和目录操作小例子
- Linux C编程--目录文件操作
- Object-C文件和目录操作
- perl 文件,目录操作
- 文件目录操作函数
- python文件目录操作
- 文件和目录操作
- 文件目录操作
- 文件和目录操作
- 文件目录操作集
- 文件目录操作编程
- 文件和目录操作
- python文件目录操作
- 文件/ 目录操作
- windows文件目录操作
- 请问屋子里有多少人
- 动态语言静态语言
- 体检之二:至尊套餐体检项目
- android学习路线
- ORA-1693: max # extents 505 错误解决办法
- C#-文件目录-文件目录操作
- DYNP_VALUES_READ
- map中用CString作为键或值,不要直接传字符窜
- Java 模拟键盘输入的小Demo
- ”世人听完先是给了5ooo多一颗丹就能培养一个剑皇级高手的丹药
- ”雷云嘴中出低吟声
- Java类集 _ Stack类
- Rails中应用auto_complete插件实现同步查询
- 逆向学习