开发者

How can I able to get all the extensions in a Directory.?

How can I able to get all the extensions in a Dir开发者_运维百科ectory. This is for vb.net windows application.

Thanks, Babu Kumarasamy.


Get all files in the directory, get the extensions from them, and remove duplicates:

Dim extensions As String() = _
  Directory.GetFiles(path) _
  .Select(Function(f As String) Path.GetExtension(f)) _
  .Distinct() _
  .ToArray()

Edit:
Changed to VB syntax


If you loop through all the files in a directory and take the extension of each file. Check if it doesn't already exist in your list and if not add it. by the time you go through all the files you will have your list.

There isn't a single method to do this.


I'd use a LINQ query with the VB.NET Group By Into syntax:

Dim extensions = From file In New DirectoryInfo(path).GetFiles() _
                 Group file By file.Extension Into Group

You can then iterate through them like so:

For Each extension In extensions
    Console.WriteLine(extension.Extension)
Next
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜