예제 #1
0
 /// <summary>
 /// 获取文件夹路径下所有类型文件url
 /// </summary>
 /// <param name="dirPath">路径</param>
 /// <param name="searchPatterns">类型数组</param>
 /// <returns>所有类型名</returns>
 public static string[] GetAllURL(string dirPath, params string[] searchPatterns)
 {
     if (!System.IO.File.Exists(dirPath))
     {
         System.IO.Directory.CreateDirectory(dirPath);
     }
     if (searchPatterns.Length <= 0)
     {
         return(null);
     }
     else
     {
         System.IO.DirectoryInfo di  = new System.IO.DirectoryInfo(dirPath);
         System.IO.FileInfo[][]  fis = new System.IO.FileInfo[searchPatterns.Length][];
         int count = 0;
         for (int i = 0; i < searchPatterns.Length; i++)
         {
             System.IO.FileInfo[] fileInfos = di.GetFiles(searchPatterns[i]);
             fis[i] = fileInfos;
             count += fileInfos.Length;
         }
         string[] files = new string[count];
         int      n     = 0;
         for (int i = 0; i <= fis.GetUpperBound(0); i++)
         {
             for (int j = 0; j < fis[i].Length; j++)
             {
                 string temp = fis[i][j].FullName;
                 files[n] = temp;
                 n++;
             }
         }
         return(files);
     }
 }