开发者

How can i get all files without file extension into an array

开发者 https://www.devze.com 2023-01-21 19:32 出处:网络
How can i get all files without file extension into an array. I will su开发者_运维百科pply the folder path.

How can i get all files without file extension into an array. I will su开发者_运维百科pply the folder path. Is this possible using Directory.GetFiles() or DirectoryInfo.GetFiles()?? Is there any alternative way?

I am using ASP.NET C#.


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.


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();
0

精彩评论

暂无评论...
验证码 换一张
取 消