當前位置:首頁 » 文件管理 » vb6遍歷文件夾

vb6遍歷文件夾

發布時間: 2025-01-12 05:58:13

Ⅰ vb6 for each 遍歷窗體中的順序是怎麼樣的

用For Each 遍歷控制項,無法預知被遍歷控制項的順序

Ⅱ VB6.0中怎樣遍歷一個路徑下的所有內容

'看申明,選擇遍歷文件或者文件夾
Public Function sDirTraV30(ByVal strpath As String, ByRef strFiles() As String, Optional isTraWholeDir As Boolean = True, Optional isRecDir As Boolean = False) As Long
Dim lmax As Long
Dim strTmp As String
Dim sDirList() As String
Dim l As Long
Dim c As Long
Dim i As Integer

If Right$(strpath, 1) <> "\" Then strpath = strpath & "\"
On Error Resume Next
strTmp = Dir(strpath, vbNormal Or vbReadOnly Or vbHidden Or vbSystem Or vbVolume Or vbDirectory)
c = 0
If Len(strTmp) > 0 And isRecDir Then
lmax = UBound(strFiles) + 1
ReDim Preserve strFiles(lmax)
strFiles(lmax) = strpath
c = c + 1
End If
ReDim sDirList(-1 To -1)

Do While Len(strTmp) > 0
If GetAttr(strpath & strTmp) And vbDirectory Then If Asc(Left(strTmp, 1)) <> 46 Then
If isTraWholeDir Then
lmax = UBound(sDirList) + 1
ReDim Preserve sDirList(-1 To lmax)
sDirList(lmax) = strpath & strTmp
Else
lmax = UBound(strFiles) + 1
ReDim Preserve strFiles(lmax)
strFiles(lmax) = strpath & strTmp
c = c + 1
End If
End If
Else
lmax = UBound(strFiles) + 1
ReDim Preserve strFiles(lmax)
strFiles(lmax) = strpath & strTmp
c = c + 1
End If
strTmp = Dir
Loop

If isTraWholeDir Then
For l = 0 To UBound(sDirList)
c = c + sDirTraV30(sDirList(l), strFiles(), isTraWholeDir, isRecDir)
Next
End If
sDirTraV30 = c
End Function

'我一個小程序中的一段代碼,使用了這個函數(遍歷文件夾),給你看看用法。

Private Sub btnLogin_Click(Index As Integer)
Dim strFiles() As String
Dim tempStr As String
Dim lstStr() As String
Select Case Index
Case 0
Picture1(1).Visible = False
Picture1(2).Visible = False
Picture1(3).Visible = False
Picture1(0).Visible = True
Case 1
Picture1(0).Visible = False
Picture1(2).Visible = False
Picture1(3).Visible = False
Picture1(1).Visible = True

Case 2
Picture1(1).Visible = False
Picture1(0).Visible = False
Picture1(3).Visible = False
Picture1(2).Visible = True

If sDirTraV30(App.Path & "\Data\HX\setting\", strFiles(), False, False) = 0 Then Exit Sub

With lstJS
.ListItems.Clear
.ColumnHeaders.Clear
.View = lvwReport
.ColumnHeaders.Add , , "序號", 550
.ColumnHeaders.Add , , "已存在角色名稱", lstJS.Width - 580
.ColumnHeaders(2).Alignment = lvwColumnCenter
End With
For i = 0 To UBound(strFiles)
strFiles(i) = Replace(strFiles(i), App.Path & "\Data\HX\setting\", "")
If StrComp(strFiles(i), "Default", vbTextCompare) <> 0 Then
If tempStr = "" Then
tempStr = strFiles(i)
Else
tempStr = tempStr & "," & strFiles(i)
End If
End If
Next

lstStr = Split(tempStr, ",")

For i = 0 To UBound(lstStr)
Set ListItemTemp = lstJS.ListItems.Add(, , i + 1)
ListItemTemp.SubItems(1) = lstStr(i)
Next

Case 3
Picture1(1).Visible = False
Picture1(2).Visible = False
Picture1(0).Visible = False
Picture1(3).Visible = True
End Select
End Sub

Ⅲ vb6 中 遍歷指定文件夾中的文本文件

SubsFile(dAsString)
DimfsoAsObject,tdAsObject,ffAsObject,ddAsObject
Setfso=CreateObject("scripting.filesystemobject")
Settd=fso.getfolder(d)
ForEachffIntd.Files
IfLCase(Right(ff.Name,4))=".txt"ThenList1.AddItemff.Path
Next
IfCheck1.Value=1Then
ForEachddIntd.subfolders
sFiledd.Path
Next
EndIf
EndSub

PrivateSubCommand3_Click()
List1.Clear
sFileText2.Text
EndSub

熱點內容
60編譯 發布:2025-09-14 14:44:14 瀏覽:738
怎麼在我的世界國際版伺服器開創造 發布:2025-09-14 14:44:11 瀏覽:36
解壓拓展怎麼選 發布:2025-09-14 14:28:00 瀏覽:221
手機無線存儲器 發布:2025-09-14 14:18:24 瀏覽:976
將編程納入 發布:2025-09-14 14:08:20 瀏覽:401
android進度條使用 發布:2025-09-14 14:01:06 瀏覽:854
怎麼看伺服器哪些埠沒有被佔用 發布:2025-09-14 14:01:06 瀏覽:229
星際方塊伺服器家園世界如何禁足 發布:2025-09-14 14:00:52 瀏覽:345
我的世界如何創建一個有模組的伺服器 發布:2025-09-14 13:42:40 瀏覽:330
安防場景如何選擇伺服器 發布:2025-09-14 13:20:48 瀏覽:741