嵌套for循环visual basic

时间:2014-09-05 19:12:38

标签: vb.net winforms

我从app.config文件中获取目录列表,然后使用我当前的目录,我正在梳理这些目录,搜索任何.ini文件并将它们添加到下拉列表中。我能够遍历第一个目录,但不能通过任何其他目录。我的循环结构有问题吗?

这是我的加载方法

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
                       Handles MyBase.Load

  'Get the current directory
  Dim curDir As String
  curDir = My.Computer.FileSystem.CurrentDirectory

  'Get the directory paths to populate dropdown with INIs
  Dim paths As String()
  paths = ConfigurationManager.AppSettings("DIRECTORY_LIST").Split(",")

  'Nested for loop to cycle through the directories and add the .inis to dropdown for each
  For Each path As String In paths
    PartNumberTextBox.Items.Add(Replace(path, "\ini\", "") + "----------------------------")
    For Each foundFile As String In My.Computer.FileSystem.GetFiles(curDir + path, Microsoft.VisualBasic.FileIO.SearchOption.SearchTopLevelOnly, "*.ini")
      Dim iniFileName As String = Replace(foundFile, curDir, "")
      PartNumberTextBox.Items.Add(iniFileName)
    Next
  Next

下拉图片,请注意其他目录(包含ini文件)不要显示

enter image description here

0 个答案:

没有答案