【问题标题】:when using Directory.GetDirectories Method is there a way to only return the name of the directories?当使用 Directory.GetDirectories 方法时,有没有办法只返回目录的名称?
【发布时间】:2020-09-28 13:25:28
【问题描述】:

我正在尝试使用目录中的文件夹名称填充组合框。 当我使用Directory.GetDirectories Method 时,它会返回整个路径。

例如,给定:

C:\Projects\test
C:\Projects\test1
C:\Projects\test2

我只想获取文件夹名称如下:

test
test1
test2

【问题讨论】:

标签: vb.net


【解决方案1】:

也许你可以试试这样的:

System.IO.Path.GetFileName(directory);

这适用于文件,但也适用于目录,System.IO.Path 会认为它是一个没有扩展名的文件,所以它可以工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-11-22
    • 2018-09-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多