遍历文件夹并判断文件格式

 

f盘下有文件夹a,a文件夹下面有2012-2-2-22-22文件夹,2012-2-2-22-22文件夹下面有3.affix1和3.his1

 

protected void button1_Click(object sender, EventArgs e)
        {
            string name="";
            DirectoryInfo theFolder = new DirectoryInfo(@"F:\a\");
            DirectoryInfo[] dirInfo = theFolder.GetDirectories();
            //遍历文件夹
            foreach (DirectoryInfo NextFolder in dirInfo)
            {
                //遍历文件夹
                //this.listBox2.Items.Add(NextFolder.Name);
                // 遍历文件夹下文件
                        FileInfo[] fileInfo = NextFolder.GetFiles();
                        foreach (FileInfo NextFile in fileInfo)  //遍历文件
                        {

 

                            name = NextFile.Name.ToString();
                            int i = name.LastIndexOf(".");
                           string ext = name.Substring(i);
                            string[] allowext = { ".his1", ".affix1" };
                            for (int a = 0; a < allowext.Length; a++)
                            {
                                if (ext == allowext[a])
                                {
                                    //  this.listBox2.Items.Add(NextFile.Name);
                                    this.listBox2.Items.Add(name);
                                }
                            }
                        }
                  
             
            }

        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值