代码改变世界

获取目录文件夹中的excel名称

2013-10-30 15:16  ゞ蓦然灬淺笑ゞ  阅读(398)  评论(0)    收藏  举报

 string folder = context.Server.MapPath("/Excel");  //获取文件夹URL
            List<string> list = new List<string>();
            //有子目录的情况
            string[] dires = Directory.GetDirectories(folder);
            foreach (string dire in dires)
            {
                string[] filepart = dire.Split('\\');
                string filename = filepart[filepart.Length - 1].ToString();//析取文件名
                GetExcelName(context);
                list.Add(filename);
            }
            //排除子目录,直接获取名称
            string[] files = Directory.GetFiles(folder);
            foreach (string file in files)
            {
                string[] filepart = file.Split('\\');
                string filename = filepart[filepart.Length - 1].ToString();
                list.Add(filename);
            }
            return list;