다음 예제에서는 DirectoryInfo 클래스를 사용하여 C:\ 디렉터리에 있는 모든 폴더를 반환합니다.
Imports statements at the top of the file.' xml:space="preserve">
Public Function GetFolders() As String ' Create a new StringBuilder, which is used ' to efficiently build strings. Dim sb As New System.Text.StringBuilder Dim dInfo As New System.IO.DirectoryInfo("c:\") ' Obtain an array of directories, and iterate through ' the array. For Each dir As System.IO.DirectoryInfo In dInfo.GetDirectories() sb.Append(dir.Name) sb.Append(Microsoft.VisualBasic.ControlChars.CrLf) Next Return sb.ToString End Function
' Place Imports statements at the top of your program. Imports System.Text Imports System.IO Imports Microsoft.VisualBasic.ControlChars
Public Function GetFolders() As String Dim sb As New StringBuilder Dim dInfo As New DirectoryInfo("c:\") For Each dir As DirectoryInfo In dInfo.GetDirectories() sb.Append(dir.Name) sb.Append(CrLf) Next Return sb.ToString End Function
Imports systxt = System.Text Imports sysio = System.IO Imports ch = Microsoft.VisualBasic.ControlChars
Public Function GetFolders() As String Dim sb As New systxt.StringBuilder Dim dInfo As New sysio.DirectoryInfo("c:\") For Each dir As sysio.DirectoryInfo In dInfo.GetDirectories() sb.Append(dir.Name) sb.Append(ch.CrLf) Next Return sb.ToString End Function
Imports strbld = System.Text.StringBuilder Imports dirinf = System.IO.DirectoryInfo