如何将没有文件扩展名的所有文件放入数组中

发布于 2024-09-29 02:07:42 字数 128 浏览 0 评论 0原文

如何将没有文件扩展名的所有文件放入数组中。我将提供文件夹路径。 使用 Directory.GetFiles() 或 DirectoryInfo.GetFiles() 可以吗?还有其他方法吗?

我正在使用 ASP.NET C#。

How can i get all files without file extension into an array. I will supply the folder path.
Is this possible using Directory.GetFiles() or DirectoryInfo.GetFiles()?? Is there any alternative way?

I am using ASP.NET C#.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

究竟谁懂我的在乎 2024-10-06 02:07:42

我猜想:(

string[] files = Directory.GetFiles(dir,"*.")

现已验证;效果很好) - 请注意,您可能需要使用 Server.MapPath 在相对站点路径和物理磁盘路径之间切换,并且 Directory 的结果.GetFiles 是完整路径。

I would guess:

string[] files = Directory.GetFiles(dir,"*.")

(now verified; that works fine) - note that you may need to use Server.MapPath to switch between relative site paths and physical disk paths, and that the results of Directory.GetFiles are full paths.

无人接听 2024-10-06 02:07:42

如果您只需要获取文件夹中所有文件的名称部分(即使是带有扩展名的文件):

string[] files = Directory.GetFiles(dir,"*.*")
                          .Select(n => Path.GetFileNameWithoutExtension(n))
                          .ToArray();

If you need to get just the name part of all files in a folder (even those with extensions):

string[] files = Directory.GetFiles(dir,"*.*")
                          .Select(n => Path.GetFileNameWithoutExtension(n))
                          .ToArray();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文