应该很简单了,不过我没学过C#,完全不知道改怎么写就一个函数,传两个参数,一个路径,一个文件后缀名, 返回一个数组/集合/vector/list?  什么都行,找出来就可以了

解决方案 »

  1.   

    Directory.GetFiles("路径名",“匹配模式”);
    返回一个字符串数组;
      

  2.   

    FileInfo fi=new FileInfo(path);string str=fi.Name.SubString(fi.Name.LastOf('.'),fi.Name.length);
      

  3.   

       string strPath = "~/fffffff/";//取出所在路径
    System.IO.File.Exists(strPath + strRFname + ".后缀"
      

  4.   


    不用考虑那个了
    string[] fl = Directory.GetFiles("C:\\Documents and Settings\\All Users\\Documents\\My Pictures\\示例图片", ".jpg");这样写不对么?  为什么取出来fl为空...
      

  5.   

    这样写吧:
    string[] res = Directory.GetFiles(filePath,"*."+lastName );
    string[] res = Directory.GetFiles(C:\\Documents and Settings\\All Users\\Documents\\My Pictures\\示例图片", "*.jpg");
      

  6.   

    匹配模式写成这个"*.jpg",顺便贴一个搜索文件夹下及其子文件夹的代码:/// <summary>
    /// 寻找指定文件夹及其子文件夹中的所有指定类型的文件名称
    /// </summary>
    /// <param name="filePath">文件路径</param>
    /// <param name="lastName">后缀名</param>
    /// <returns></returns>
    public static string[] GetAllFiles(string filePath ,string lastName)
    {
    DirectoryInfo sourceFilecInfo = new DirectoryInfo (filePath )  ;
     //记录当前目录下的所有文件,不包括子文件夹中的文件
    FileInfo[] allFiles  = sourceFilecInfo .GetFiles () ;
    //记录当前文件夹中的子文件夹
    DirectoryInfo[]  allDirectory  = sourceFilecInfo .GetDirectories ()  ;
    //然后对每个依次进行判断其后缀名
    string[] res = Directory.GetFiles(filePath,"*."+lastName );

    //递归调用该方法来去子文件中的文件进行搜索
    for (int i = 0 ; i <allDirectory .Length ; i ++ )
    {
    string[] tempRes = GetAllFiles (allDirectory [i].FullName ,lastName );
    //合并结果 res 与 tempRes
    string[] combination = new string[res.Length +tempRes.Length ] ;
    int count = 0 ;
    foreach (string s in res )
    {
    combination [count ++]= s ;
    }
    foreach (string s in tempRes )
    {
    combination [count ++] = s ;
    }
    res = combination ;
    }
    return res ;
    }调用:
    string[] s = GetAllFiles (@"D:\Backup\我的文档\","txt");
    记住,调用的时候输入的地址后面一定要加一个 "\",或者自己在程序里面改,默认加上也可以
      

  7.   

    匹配模式写成这个"*.jpg",顺便贴一个搜索文件夹下及其子文件夹的代码:/// <summary>
    /// 寻找指定文件夹及其子文件夹中的所有指定类型的文件名称
    /// </summary>
    /// <param name="filePath">文件路径</param>
    /// <param name="lastName">后缀名</param>
    /// <returns></returns>
    public static string[] GetAllFiles(string filePath ,string lastName)
    {
    DirectoryInfo sourceFilecInfo = new DirectoryInfo (filePath )  ;
     //记录当前文件夹中的子文件夹
    DirectoryInfo[]  allDirectory  = sourceFilecInfo .GetDirectories ()  ;
    //然后对每个依次进行判断其后缀名
    string[] res = Directory.GetFiles(filePath,"*."+lastName );

    //递归调用该方法来去子文件中的文件进行搜索
    for (int i = 0 ; i <allDirectory .Length ; i ++ )
    {
    string[] tempRes = GetAllFiles (allDirectory [i].FullName ,lastName );
    //合并结果 res 与 tempRes
    string[] combination = new string[res.Length +tempRes.Length ] ;
    int count = 0 ;
    foreach (string s in res )
    {
    combination [count ++]= s ;
    }
    foreach (string s in tempRes )
    {
    combination [count ++] = s ;
    }
    res = combination ;
    }
    return res ;
    }调用:
    string[] s = GetAllFiles (@"D:\Backup\我的文档\","txt");
    记住,调用的时候输入的地址后面一定要加一个 "\",或者自己在程序里面改,默认加上也可以