在目录中查找所有目录,仅返回名称 [英] Find all directories in directory and return only name

查看:65
本文介绍了在目录中查找所有目录,仅返回名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在vb.net的一个目录中找到所有目录。

I want to find all directories in one directory in vb.net.

我找到了一个脚本:

For Each Dir As String In Directory.GetDirectories(FolderName)
    ComboBox3.Items.Add(Dir)
Next

它返回路径的全名,但我希望它仅返回路径名。

It returns full name of path, but I want it to return only name of path.

推荐答案

最简单的方法是使用 System.IO.DirectoryInfo

    For Each Dir As String In System.IO.Directory.GetDirectories(FolderName)
        Dim dirInfo As New System.IO.DirectoryInfo(Dir)
        ComboBox3.Items.Add(dirInfo.Name)
    Next

(显然,您可以手动解析它,然后提取出最后一个'\'之后的文本,但我认为上面的内容更具可读性)

(Obviously, you could parse it manually and extract out the text following the final '\', but I believe that the above is more readable)

这篇关于在目录中查找所有目录,仅返回名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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