Obtain a listing of files for a specified directory and place them in a StringBuilder, Windows Clipboard and a Listbox.
[C#]
//<-- Snippet Start --> // DESCRIPTION: // Obtain a listing of files for a specified directory and place them in a // StringBuilder, Windows Clipboard and a Listbox. // System.IO.DirectoryInfo directoryInfo = new System.IO.DirectoryInfo("directory"); System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder(2000); if (directoryInfo != null) { System.IO.FileInfo[] fileInfo = directoryInfo.GetFiles(); for (int i = 0; i < fileInfo.GetUpperBound(0); i++) { $listBox1$.Items.Add(fileInfo[i].FullName); stringBuilder.Append(fileInfo[i].Name + System.Environment.NewLine); } System.Windows.Forms.Clipboard.SetDataObject(stringBuilder.ToString()); } //<-- Snippet End -->
[Visual Basic .NET]
'<-- Snippet Start --> ' DESCRIPTION: ' Obtain a listing of files for a specified directory and place them in a ' StringBuilder, Windows Clipboard and a Listbox. Dim directoryInfo As System.IO.DirectoryInfo = New System.IO.DirectoryInfo("directory") Dim stringBuilder As System.Text.StringBuilder = New System.Text.StringBuilder(2000) If Not (directoryInfo Is Nothing) Then Dim fileInfo As System.IO.FileInfo() = directoryInfo.GetFiles Dim i As System.Int32 For i = 0 To fileInfo.GetUpperBound(0) $Listbox1$.Items.Add(fileInfo(i).FullName) stringBuilder.Append(fileInfo(i).Name + System.Environment.NewLine) Next i System.Windows.Forms.Clipboard.SetDataObject(stringBuilder.ToString) End If '<-- Snippet End -->