Private Sub FillList(dirName As String)
 '处理返回的目录信息
 Dim i As Integer, i1 As Integer, i2 As Integer, j As Integer
 Dim nodexx As ListItem, ss As String, filen As String
 Dim TL As Boolean
 ListView1.ListItems.Clear
  i2 = 0
  
1:
 i1 = Len(dirName)
 TL = False
 For i = 1 To i1
   ss = Mid(dirName, i, 1)
   aa = Asc(ss)
 If aa = 13 Then
 
    filen = Mid(dirName, 1, i - 1)
    If Len(filen) >= 1 Then
         i2 = i2 + 1
         For j = 1 To Len(filen)
         If Mid(filen, j, 1) = "/" Then
         TL = True
         filen = Mid(filen, 1, j - 1)
         Exit For
    End If
    Next j
    If TL Then
       Set nodexx = ListView1.ListItems.Add(i2, filen, filen, 1)
    Else
       Set nodexx = ListView1.ListItems.Add(i2, filen, filen, 2)
    End If
     ListView1.View = 0
     dirName = Mid(dirName, i + 2, i1 - i - 2)
    GoTo 1
    End If
 End If
Next i
End Sub

解决方案 »

  1.   

    你可以使用split函数分割字符串:dim strFiles() as stringstrFiles = split(dirname, chr(13))
    for i=0 to Ubound(strFiles)
      ......
    next i下面代码
        For j = 1 To Len(filen)
          If Mid(filen, j, 1) = "/" Then
             TL = True
             filen = Mid(filen, 1, j - 1)
             Exit For
          End If
        Next j
    可以用
    n = instr(1, filen, "/")
    if n>0 then
       TL = True
       filen = left(filen, n - 1)
    end if
    来取代。尽可能不用循环。