如何获取具有相同扩展名的文件并在列表中查看它们? [英] How to grab files that have the same extension and view them in a list?

查看:77
本文介绍了如何获取具有相同扩展名的文件并在列表中查看它们?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我想知道如何选择一个文件夹,然后我希望我的应用程序扫描该文件夹,说出其中的任何mp3文件并查看列表中的歌曲。

i知道如何选择一条路,我只想知道如何让我的应用程序只查找mp3文件。

谢谢

so i want to know how to select a folder, then i want my app to scan that folder for say any mp3 file in it and view the songs in a list.
i know how to select a path, i just want to know how can i make my app look for only mp3 files.
thanks

推荐答案



好​​了,你所要做的就是在IO中使用GetFiles方法.Directory获取该目录中的路径和匹配扩展名。

VB.NET:

Hi,
Well, all you have to do is use the GetFiles method in IO.Directory to get the path and matching extensions in that directory.
VB.NET:
Function GetMatchingExtensions(ByVal Filter As String, ByVal Directory As String, ByVal SearchSubDirectories As Boolean) As String()
        If SearchSubDirectories Then
            Return IO.Directory.GetFiles(Directory, Filter, IO.SearchOption.AllDirectories)
        Else
            Return IO.Directory.GetFiles(Directory, Filter, IO.SearchOption.TopDirectoryOnly)
        End If
    End Function





调用此列表并列出列表框中的所有内容:



Call upon this and list everything in listbox by:

For Each file As String In GetMatchingExtensions("FILTER", "DIR", False)
            ListBox1.Items.Add(file)
        Next





如果需要,只需将其转换为C#。

问候,
iProgramIt



Just convert this to C# if you want.
Regards,
iProgramIt


这篇关于如何获取具有相同扩展名的文件并在列表中查看它们?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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