|
|
Title | List information about the files in a directory in a ListView using Visual Basic 2005 |
Description | This example shows how to list information about the files in a directory in a ListView using Visual Basic 2005. This example uses My.Computer.FileSystem.GetFiles to list the files. |
Keywords | directory, list files, ListView, My, My.Computer, FileSystem, GetFiles, FileInfo, GetFileInfo |
Categories | Controls |
|
|
The program uses My.Computer.FileSystem.GetFiles to list the files in the directory. For each file name, it uses My.Computer.FileSystem.GetFileInfo to get a FileInfo object for the file. It uses that object to get the file's size, creation date, and last modification date.
|
|
Private Sub btnListFiles_Click(ByVal sender As _
System.Object, ByVal e As System.EventArgs) Handles _
btnListFiles.Click
lvwFileInfo.Items.Clear()
For Each file_name As String In _
My.Computer.FileSystem.GetFiles(txtDirectory.Text)
Dim file_info As System.IO.FileInfo = _
My.Computer.FileSystem.GetFileInfo(file_name)
Dim new_item As ListViewItem = _
lvwFileInfo.Items.Add(file_name)
new_item.SubItems.Add(file_info.Length)
new_item.SubItems.Add(file_info.CreationTime.ToString())
new_item.SubItems.Add(file_info.LastWriteTime.ToString())
Next file_name
End Sub
|
|
|
|
|
|