编程语言
首页 > 编程语言> > C#读取某个目录下的所有excel文件名

C#读取某个目录下的所有excel文件名

作者:互联网

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OleDb;
using System.IO;
using System.Collections;
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string SourceExcelPath = @"E:\C# Projects\ConsoleApplication1\";
            DirectoryInfo mydir = new DirectoryInfo(SourceExcelPath);
            if (mydir.GetFiles().Length <= 0)
            {
                Console.WriteLine("文件夹里面没有文件");
            }
            else
            {
                Console.WriteLine("文件夹里面有文件");
            }
            ArrayList list = new ArrayList();
            foreach (FileSystemInfo fsi in mydir.GetFileSystemInfos())
            {
                if (fsi is FileInfo)//
                {
                    FileInfo fi=(FileInfo)fsi;
                    if(fi.Extension.ToUpper()==".XLSX")//
                    {
                        list.Add(fi.Name);
                    }
                }
            }
           // Console.WriteLine(list);
           //遍历对象的
            foreach(string str in list)
            {
                Console.WriteLine(str.ToString()+"");//遍历目录先所有的.XlSX文件
            }

        }
    }
}

标签:ConsoleApplication1,读取,C#,excel,System,mydir,SourceExcelPath,using
来源: https://blog.csdn.net/qq_38413756/article/details/114300277