This document is archived and information here might be outdated. Recommended version. |
ArcObjects Help for .NET developers > ESRI.ArcGIS.Snippets > Snippets > Statements - List Files into StringBuilder, Clipboard and ListBox Snippet (ArcObjects .NET 10.4 SDK) |
Obtain a listing of files for a specified directory and place them in a StringBuilder, Windows Clipboard and a Listbox.
//<-- 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 -->
'<-- 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 -->