VB.NET获取目录文件夹名称
2个回答
展开全部
先用System.IO.Directory.GetDirectories函数获取子目录的名称(包括其路径),再用System.IO.Path.GetFileName获取子目录的名称。下面是代码:
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
For Each s In System.IO.Directory.GetDirectories("C:\Windows")
Console.WriteLine(System.IO.Path.GetFileName(s))
Next
End Sub
下面是部分输出:
Application Data
AppPatch
assembly
BOCNET
Boot
Branding
ConfigSetRoot
Cursors
Debug
DigitalLocker
Downloaded Installations
Downloaded Program Files
ehome
en-US
Fonts
Globalization
Help
...
可能有更简洁的方法,你可以到MSDN看看
System.IO.Directory.GetDirectories:http://msdn.microsoft.com/zh-cn/library/c1sez4sc.aspx
System.IO.Path.GetFileName:http://msdn.microsoft.com/zh-cn/library/system.io.path.getfilename.aspx
通用 I/O 任务:http://msdn.microsoft.com/zh-cn/library/ms404278.aspx
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
For Each s In System.IO.Directory.GetDirectories("C:\Windows")
Console.WriteLine(System.IO.Path.GetFileName(s))
Next
End Sub
下面是部分输出:
Application Data
AppPatch
assembly
BOCNET
Boot
Branding
ConfigSetRoot
Cursors
Debug
DigitalLocker
Downloaded Installations
Downloaded Program Files
ehome
en-US
Fonts
Globalization
Help
...
可能有更简洁的方法,你可以到MSDN看看
System.IO.Directory.GetDirectories:http://msdn.microsoft.com/zh-cn/library/c1sez4sc.aspx
System.IO.Path.GetFileName:http://msdn.microsoft.com/zh-cn/library/system.io.path.getfilename.aspx
通用 I/O 任务:http://msdn.microsoft.com/zh-cn/library/ms404278.aspx
展开全部
Dim dir As New IO.DirectoryInfo("C:\TDDownload")
// 目录下就一个文件夹
If dir.GetDirectories.Length > 0 Then
MessageBox.Show(dir.GetDirectories.GetValue(0).ToString())
End If
// 目录下多个文件夹
'For Each d As IO.DirectoryInfo In dir.GetDirectories
' MessageBox.Show(d.FullName)
'Next
继续追问: 谢了!
Dim dirs As String() = Directory.GetFileSystemEntries("C:\Documents and Settings\All Users\Application Data\Kaspersky Lab Setup Files")
Label1.Text = Path.GetFileName(dirs(0))
// 目录下就一个文件夹
If dir.GetDirectories.Length > 0 Then
MessageBox.Show(dir.GetDirectories.GetValue(0).ToString())
End If
// 目录下多个文件夹
'For Each d As IO.DirectoryInfo In dir.GetDirectories
' MessageBox.Show(d.FullName)
'Next
继续追问: 谢了!
Dim dirs As String() = Directory.GetFileSystemEntries("C:\Documents and Settings\All Users\Application Data\Kaspersky Lab Setup Files")
Label1.Text = Path.GetFileName(dirs(0))
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询