且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

C#获取所有文件名而不目录扩展

更新时间:2022-10-15 11:50:22

  Directory.GetFiles(mypath中的* .txt)
。选择(Path.GetFileNameWithoutExtension)
。选择(p =指p。子(1))//每评论


Im looking for a way to read ALL txt files in a directory path without their extensions into an array. Ive looked through the path.getFileNameWithoutExtension but that only returns one file. I want all the *.txt file names from a path i specify

THanks

Directory.GetFiles(myPath, "*.txt")
    .Select(Path.GetFileNameWithoutExtension)
    .Select(p => p.Substring(1)) //per comment