怎么得到指定磁盘下所有的文件夹
我想得到一个磁盘下所有的文件夹该怎么写啊 ? 问题点数:30、回复次数:7Top
1 楼3tzjq(永不言弃)回复于 2005-05-16 15:53:25 得分 0
抄了一段来自MSDN的VB.Net代码:
Private Sub AddFiles(ByVal nod As TreeNode)
Dim strPath As String = nod.FullPath
Dim strFile As String
With nod
For Each strFile In Directory.GetFiles(strPath)
With nod.Nodes.Add(Path.GetFileName(strFile))
.Tag = ItemType.File
End With
Next
End With
End Sub
Private Sub AddFolders(ByVal nod As TreeNode)
Dim strPath As String = nod.FullPath
Dim strDir As String
With nod
For Each strDir In Directory.GetDirectories(strPath)
' Path.GetFileName returns just the file name portion
' of the full path returned from the GetDirectories
' method.
With nod.Nodes.Add(Path.GetFileName(strDir))
' Keep track that this item
' is, in fact, a directory. We'll need
' that info later.
.Tag = ItemType.Directory
' Add the DUMMY node, so the + sign appears.
.Nodes.Add(DUMMY)
End With
Next
End With
End Sub
Top
2 楼huangkc(软贱&henchman)回复于 2005-05-16 16:03:56 得分 10
string strdir="路径";
DirectoryInfo dircol;
DirectoryInfo dirinfo = new DirectoryInfo(strdir);
foreach( DirectoryInfo dirinfo in dirinfo .GetDirectories)
{
dircol= (DirectoryInfo)dirinfo ;
string xxx= dirdircol.Name //目录名
...
}Top
3 楼ljc_zy(彷徨)回复于 2005-05-16 16:14:02 得分 0
接分.Top
4 楼oyljerry(【勇敢的心】→ ㊣提拉米苏√㊣)回复于 2005-05-16 16:19:04 得分 0
CFileFind遍历Top
5 楼pingnt(淡蓝色的雪)回复于 2005-05-16 16:19:21 得分 0
Private Sub AddFiles(ByVal nod As TreeNode)
Dim strPath As String = nod.FullPath
Dim strFile As String
With nod
For Each strFile In Directory.GetFiles(strPath)
With nod.Nodes.Add(Path.GetFileName(strFile))
.Tag = ItemType.File
End With
Next
End With
End Sub
Private Sub AddFolders(ByVal nod As TreeNode)
Dim strPath As String = nod.FullPath
Dim strDir As String
With nod
For Each strDir In Directory.GetDirectories(strPath)
' Path.GetFileName returns just the file name portion
' of the full path returned from the GetDirectories
' method.
With nod.Nodes.Add(Path.GetFileName(strDir))
' Keep track that this item
' is, in fact, a directory. We'll need
' that info later.
.Tag = ItemType.Directory
' Add the DUMMY node, so the + sign appears.
.Nodes.Add(DUMMY)
End With
Next
End With
End Sub
Top
6 楼RockyZhang(Rocky)回复于 2005-05-16 16:43:06 得分 10
写一个递归,用System.IO.Directory.GetDirectory方法遍历.Top
7 楼wf5360308(冷月孤峰)回复于 2005-05-18 21:00:38 得分 10
用DirectoryInfo。
MSDN上面有列子的Top




