Get Files from folder - CSharp File IO

CSharp examples for File IO:Directory

Description

Get Files from folder

Demo Code


using System.Collections.Generic;

public class Main{

        public static List<string> GetFiles(string path, string pattern)
        {/*from  ww w  .  j  a  v a  2 s. c o m*/
            string[] array = System.IO.Directory.GetFiles(path, pattern);
            if (array == null || array.Length == 0) return null;

            List<string> list = new List<string>();
            foreach (string item in array)
            {
                string[] arr = item.Split('\\');
                list.Add(arr[arr.Length - 1]);
            }
            return list;
        }
}

Related Tutorials