Function ty(ByVal mc As String) As Boolean
Open mc For Input As #1
Do While Not EOF(1)
Line Input #1, fg
If Len(fg) <> 0 Then
If InStr(fg, "你的内容") > 0 Then
ty = True
Exit Do
End If
End If
Loop
Close #1
End Function
Function bianli(Path) As Integer
Dim fso As New FileSystemObject
Dim objFolder As Folder
Set objFolder = fso.GetFolder(Path)
For Each objFile In objFolder.Files
If InStr(LCase(objFile.Name), ".txt") > 0 Then
If ty(objFolder.Path & "\" & objFile.Name) Then
MsgBox objFolder.Path & "\" & objFile.Name & " ok "
你处理内容
End If
End If
Next
For Each objFolder In objFolder.SubFolders
bianli (objFolder)
Next
Set objFolder = Nothing
Set objSubFolders = Nothing
Set fso = Nothing
End Function
Function bianli(Path) As Integer
Dim fso As New FileSystemObject
Set objFolder = fso.GetFolder(Path)
For Each objFile In objFolder.Files
If InStr(objFile.Name, ".txt") > 0 Then
If ty(thing.Name) Then
MsgBox thing.Name & "ok"
End If
End If
Next
For Each objFolder In objFolder.SubFolders
J = J + 1
bianli (objFolder)
Next
Set objFolder = Nothing
Set objSubFolders = Nothing
Set fso = Nothing
bianli = K
End Function
wangtiecheng的遍历文件代码有点问题
bianli("d:") or bianli("d:\temp")
Function bianli(Path) As Integer
Dim fso As New FileSystemObject
Set objFolder = fso.GetFolder(Path)
For Each objFile In objFolder.Files
K = K + 1
Next
For Each objFolder In objFolder.SubFolders
J = J + 1
bianli (objFolder)
Next
Set objFolder = Nothing
Set objSubFolders = Nothing
Set fso = Nothing
bianli = K
End Function
1、TXT文件格式及内容;
2、假设在目录中没有子目录:
Dim df As New FileSystemObject
'创建一个Folder对象
Set MyFolder = df.GetFolder("d:\zz")
'循环显示其中文件
For Each thing In MyFolder.Files
MsgBox thing.Name
If InStr(thing.Name, ".txt") > 0 Then
If ty(thing.Name) Then
MsgBox thing.Name & "ok"
End If
End If
Next
Function ty(ByVal mc As String) As Boolean
Open "你的路径" & mc For Input As #1 ' 打开输出文件。
Do While Not EOF(1)
Line Input #1, fg
If Len(fg) <> 0 Then
If InStr(fg, "你查找的内容,出可以用参数") > 0 Then
ty = True
Exit Do
End If
End If
Loop
Close #1
End Function
function bianli(path)
set fso=createobject("scripting.filesystemobject")
on error resume next
set objFolder=fso.GetFolder(path)
set objSubFolders=objFolder.Subfolders
for each objSubFolder in objSubFolders
if right(path,1)<>"\" then
nowpath=path + "\" + objSubFolder.name
else
nowpath=path + objSubFolder.name
end if
Response.Write nowpath
set objFiles=objSubFolder.Files
for each objFile in objFiles
Response.Write "<br>"
Response.Write objFile.name
next
Response.Write "<hr>"
if objSubFolder.attributes<>16 then bianli(nowpath)
'bianli(nowpath)
next
Response.Write path1
for each objFile1 in objFolder.Files
Response.Write "<br>"
Response.Write objFile1.name
next
Response.Write "<hr>"
set objFolder=nothing
set objSubFolders=nothing
set fso=nothing
end function