zoukankan      html  css  js  c++  java
  • 用C#列出指定目录下的所有指定扩展名(多个扩展名)的文件

    以前学过一点C#,好久没有用了,没有想到 ,还真的忘了不少的东西,(难道真的老了??),为了写一个列出指定目录下的,所有指定扩展名(多个扩展名)的文件的小函数 竟然花了我两个小时,要用到的函数都要去翻一遍MSDN,看来真的是三天不练 手就生啊, 写了半天,写出来的东西自己还是不怎么满意,还望大家批评指正,源码如下...

      private Array GetAllFiles(string strpath)
      
    {
       DirectoryInfo di
    =new DirectoryInfo(strpath);
       FileInfo[] result
    =di.GetFiles();
       
    string strExtFilter=".jpg,.bmp,.gif";//需要列出文件的扩展名
       ArrayList AL=new ArrayList(result);
       
    int num=AL.Count;
       
    int count=0;
       
    for(int i=0;i   {
        FileInfo sf
    =(FileInfo)AL[count];
        
    if((strExtFilter.IndexOf(sf.Extension.ToLower())==-1|| (sf.Extension==""))//当前文件的扩展名存在在过滤列表中
        {
         AL.Remove(sf);
    //如果不存在就删去此项
         count--;
        }

        count
    ++;
       }

       
       
    return AL.ToArray();
      }

  • 相关阅读:
    自定义view分析-Pull-to-Refresh.Rentals-Android
    laucher-icon的加载过程
    android shape 布局文件
    android canvas
    解释器模式(Interpreter)
    中介者模式(Mediator)
    Code obfuscation
    Table Tennis Game 2
    最小公倍数的对数
    C语言基础
  • 原文地址:https://www.cnblogs.com/9527/p/47785.html
Copyright © 2011-2022 走看看