Ad Code

Responsive Advertisement

How To Read Files With Given Extension In All Directories In Given Path

To read all the files with ".csv" extension in all the directories under a folder selected through FileBrowseDialog, the following code will work:

Imports System.IO.FileInfo

Imports System.IO

Dim Dir As String

Dim fni As FileInfo

lstDirList.Items.Clear()

For Each Dir In System.IO.Directory.GetDirectories(folderDlg.SelectedPath)

For Each fi In System.IO.Directory.GetFiles(Dir)

fni = My.Computer.FileSystem.GetFileInfo(fi)

If fni.Extension = ".csv" Then

stDirList.Items.Add(fi)

End If

Next

Next

You should also note how to:

  • Get names of all directories in a path
  • Names of all files in these directories iteratively
  • Information about a file
  • Comparison of file extension with desired one
  • How to clear data items from a list box and how to add items to listbox

Post a Comment

0 Comments