Accessing a list of files with System.IO.Directory.GetFiles(path) & and examine properties of each file
 Sub FileLister()
   'creating a DirectoryInfo object
   Dim mydocs As String
   Dim mydir As System.IO.DirectoryInfo
   mydocs = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
   mydir = New System.IO.DirectoryInfo(mydocs)
   ' getting the files in the directory, their names and size
   Dim fio As IO.FileInfo() = mydir.GetFiles()
   Dim file As IO.FileInfo
   For Each file In fio
      Console.WriteLine("File Name: {0} Size: {1}  ", file.Name, file.Length)
   Next file
 End Sub

Output:

File Name: change.txt Size: 1011  
File Name: desktop.ini Size: 402  
File Name: test.txt Size: 120  
File Name: TheLonelyProgrammer.txt Size: 24  
File Name: Viet1.rtf Size: 96289  
Here we are using System.IO.Directory to obtain the list of files The System.IO.FileInfo class provides not only a convenient list of files in a given path but also useful information about each file in the list, such as extension, last access date, creation time, last write time, file attributes, etc Interestingly the FileInfo class provides methods for opening and writing to files, encrypting and decrypting files and many other methods that are identical to the System.IO.File class

































































































600

1200

1800

2400

3000

3600

4200

4800

5400

6000

6600

7200

7800

8400

9000

9600

10200

10800

11400

12000

12600

13200

13800

14400

15000

15600

16200

16800

17400

18000

18600

19200

19800

20400

10/24/2015
TheLonelyProgrammer.Net
Alone in a sea of non-programmers
Home File Copy Path List Drives List Files Special Folders Accessing and changing file times