C#获取所有文件名而不目录扩展 [英] C# Get All file names without extension from directory

查看:192
本文介绍了C#获取所有文件名而不目录扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

林寻找一种方式来读取一个目录路径中所有txt文件未经其扩展到一个数组。香港专业教育学院通过path.getFileNameWithoutExtension看了,但只返回一个文件。我想从一个路径中的所有* .txt文件名我指定



感谢


解决方案

  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

这篇关于C#获取所有文件名而不目录扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆