为什么别人CPU只有30%,而我有100%,这如何是好呀? 我的原码如下: Public Sub Search(ByVal sRoot As String, ByVal lvw As ListView) Dim Fld As Scripting.Folder Dim Fil As Scripting.File Dim Ts As TextStream Dim sFileExnName As String Dim pos As Long Dim ls As ListItem Dim fldCurPath As Folder Dim sTagString As String
Set fldCurPath = Fso.GetFolder(sRoot) For Each Fil In fldCurPath.Files frmMain.lblProcessed.Caption = Fil.Path frmMain.lblProcessed.Refresh sFileExnName = UCase$(Fso.GetExtensionName(Fil.Path)) If sFileExnName = "HTML" Or sFileExnName = "HTM" Or sFileExnName = "ASP" Then Set Ts = Fil.OpenAsTextStream(ForReading) Do While Not Ts.AtEndOfStream sTagString = Ts.ReadLine() pos = InStr(1, sTagString, SearchString) If pos > 0 Then Set ls = lvw.ListItems.Add(, , Fil.Name) ls.ListSubItems.Add , , Fil.Path Count = Count + 1 Call ClearNimdaJS(Fil.Path, Ts.Line) End If Loop Ts.Close Set Ts = Nothing End If Next Fil
For Each Fld In fldCurPath.SubFolders Call Search(Fld.Path, lvw) Next Fld frmMain.lblProcessed.Caption = "" End Sub
kimryo(轻*轻*前*轻*重) 很对,不能用CreateObject的方法!小心内存溢出。 放两个控件,一个FileList(fileSearchFiles) 一个DirList(dirSearchFiles)然后这样: Private Sub SearchFiles(ByVal szStartDir As String) Dim i As Long, t As Stringt = dirSearchFiles.PathdirSearchFiles.Path = szStartDir fileSearchFiles.Path = szStartDirFor i = 0 To fileSearchFiles.ListCount - 1 '处理文件 'szStartDir, fileSearchFiles.List(i) If bolStopSearch Then Exit For DoEvents Next For i = 0 To dirSearchFiles.ListCount - 1 If bolStopSearch Then Exit For SearchFiles dirSearchFiles.List(i) DoEvents NextdirSearchFiles.Path = t End Sub
http://www.csdn.net/expert/topic/532/532425.xml
我的原码如下:
Public Sub Search(ByVal sRoot As String, ByVal lvw As ListView)
Dim Fld As Scripting.Folder
Dim Fil As Scripting.File
Dim Ts As TextStream
Dim sFileExnName As String
Dim pos As Long
Dim ls As ListItem
Dim fldCurPath As Folder
Dim sTagString As String
Set fldCurPath = Fso.GetFolder(sRoot)
For Each Fil In fldCurPath.Files
frmMain.lblProcessed.Caption = Fil.Path
frmMain.lblProcessed.Refresh
sFileExnName = UCase$(Fso.GetExtensionName(Fil.Path))
If sFileExnName = "HTML" Or sFileExnName = "HTM" Or sFileExnName = "ASP" Then
Set Ts = Fil.OpenAsTextStream(ForReading)
Do While Not Ts.AtEndOfStream
sTagString = Ts.ReadLine()
pos = InStr(1, sTagString, SearchString)
If pos > 0 Then
Set ls = lvw.ListItems.Add(, , Fil.Name)
ls.ListSubItems.Add , , Fil.Path
Count = Count + 1
Call ClearNimdaJS(Fil.Path, Ts.Line)
End If
Loop
Ts.Close
Set Ts = Nothing
End If
Next Fil
For Each Fld In fldCurPath.SubFolders
Call Search(Fld.Path, lvw)
Next Fld
frmMain.lblProcessed.Caption = ""
End Sub
CString Search_m_path;
HANDLE fhwnd=FindFirstFile((LPCTSTR)(path+_T("\\*.*")),fs);
if(!fhwnd)
return;.
do{
Search_m_path.Format("%s",fs->cFileName);
//::SendMessage(m_StatusBar,SB_SETTEXT,(WPARAM)0,(LPARAM)(LPCTSTR)("搜索:"+path+Search_m_path));
if(Search_m_path.GetAt(Search_m_path.GetLength()-1)=='\\')
Search_m_path.Delete(Search_m_path.GetLength()-1);
if((fs->dwFileAttributes&FILE_ATTRIBUTE_SYSTEM) || Search_m_path=="." || Search_m_path=="..")
continue;
if((fs->dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))
EnumMP3File(path+"\\"+Search_m_path); if(ConfirmExtIsMP3(fs->cFileName))
AddOneItemToTVC(path+"\\"+Search_m_path);
}while(FindNextFile(fhwnd,fs));
FindClose(fs); delete fs;
CloseHandle(fhwnd);不好意思,现成的代码只有VC的,具体就是FindFirstFile、FindNextFile和CloseHandle等函数的调用。
放两个控件,一个FileList(fileSearchFiles)
一个DirList(dirSearchFiles)然后这样:
Private Sub SearchFiles(ByVal szStartDir As String)
Dim i As Long, t As Stringt = dirSearchFiles.PathdirSearchFiles.Path = szStartDir
fileSearchFiles.Path = szStartDirFor i = 0 To fileSearchFiles.ListCount - 1
'处理文件
'szStartDir, fileSearchFiles.List(i) If bolStopSearch Then Exit For
DoEvents
Next
For i = 0 To dirSearchFiles.ListCount - 1
If bolStopSearch Then Exit For
SearchFiles dirSearchFiles.List(i)
DoEvents
NextdirSearchFiles.Path = t
End Sub