以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  [求助]文件递归怎样应用  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=115544)

--  作者:jyh7081
--  发布时间:2018/3/8 19:44:00
--  [求助]文件递归怎样应用

原贴mark word高亮查找 :http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=70797&authorid=0&page=0&star=2

 

怎样把查找的目录,包括目录下的各级子目录?

 

Dim app As New MSWord.Application
try
    Dim dlg As New FolderBrowserDialog
    If dlg.ShowDialog = DialogResult.Ok Then
        MessageBox.Show("需要检索的文档目录是:" & dlg.SelectedPath,"提示")
    End If
    Dim s As String = ""
    For Each file As String In FileSys.GetFiles(dlg.SelectedPath)
        If file.ToLower.EndsWith(".doc") Then
            Dim doc = app.Documents.Open(file)
            Dim gjzs As String = "Test|Abcdefg|test"
            Dim flag As Boolean = False
            For Each gjz As String In gjzs.split("|")
                app.ActiveWindow.Selection.WholeStory
                With app.ActiveWindow.Selection.Find
                    .HitHighlight(gjz, RGB(255, 255, 0), , , , , , , True)
                End With
                If app.ActiveWindow.Selection.Find.Execute Then flag = True
            Next
            If flag = False  Then
                Doc.close
            Else
                s = s & IIF(s>"", chr(13), "") & file
            End If
        End If
    Next
    If s > "" Then
        MessageBox.Show("共计找到包含关键字的文档有" & s.Split(chr(13)).Length & "个,目录如下:" & vbcrlf & s,"关键字文档查找",MessageBoxButtons.OK,MessageBoxIcon.None)
        app.Visible = True
    Else
        MessageBox.Show("没有找到包含关键字的文档","关键字文档查找",MessageBoxButtons.OK,MessageBoxIcon.None)
        app.quit
    End If
   
catch ex As exception
    msgbox(ex.message)
    app.Quit
finally
End try

 


--  作者:有点甜
--  发布时间:2018/3/8 21:09:00
--  

参考

 

 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:文件递归.table


--  作者:jyh7081
--  发布时间:2018/3/9 16:47:00
--  

甜老师好,代码没改好,麻烦老师看一下。

 

Dim app As New MSWord.Application
try
    Dim dlg As New FolderBrowserDialog
    If dlg.ShowDialog = DialogResult.Ok Then
        MessageBox.Show("需要检索的文档目录是:" & dlg.SelectedPath,"提示")
    End If
    Dim s As String = ""
    \'For Each file As String In FileSys.GetFiles(dlg.SelectedPath)
    Dim ls As new List(Of String)
    Functions.Execute("递归", dlg.SelectedPath, ls)
    \'msgbox(String.join("|", ls.ToArray))
    For Each ss As String In ls.ToArray       
        For Each file As String In ss           
            If file.ToLower.EndsWith(".doc") Then
                Dim doc = app.Documents.Open(file)
                Dim gjzs As String = "济南|Abcdefg|test"
                Dim flag As Boolean = False
                For Each gjz As String In gjzs.split("|")
                    app.ActiveWindow.Selection.WholeStory
                    With app.ActiveWindow.Selection.Find
                        .HitHighlight(gjz, RGB(255, 255, 0), , , , , , , True)
                    End With
                    If app.ActiveWindow.Selection.Find.Execute Then flag = True
                Next
                If flag = False  Then
                    Doc.close
                Else
                    s = s & IIF(s>"", chr(13), "") & file
                End If
            End If
        Next
    Next
    If s > "" Then
        MessageBox.Show("共计找到包含关键字的文档有" & s.Split(chr(13)).Length & "个,目录如下:" & vbcrlf & s,"关键字文档查找",MessageBoxButtons.OK,MessageBoxIcon.None)
        app.Visible = True
    Else
        MessageBox.Show("没有找到包含关键字的文档","关键字文档查找",MessageBoxButtons.OK,MessageBoxIcon.None)
        app.quit
    End If
   
catch ex As exception
    msgbox(ex.message)
    app.Quit
finally
End try

 

 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:文件递归+查找.table


--  作者:有点甜
--  发布时间:2018/3/9 18:36:00
--  

Dim app As New MSWord.Application
try
    Dim dlg As New FolderBrowserDialog
    If dlg.ShowDialog = DialogResult.Ok Then
        MessageBox.Show("需要检索的文档目录是:" & dlg.SelectedPath,"提示")
    End If
    Dim s As String = ""
   
    Dim ls As new List(Of String)
    Functions.Execute("递归", dlg.SelectedPath, ls)
   
    For Each file As String In ls
        If file.ToLower.EndsWith(".doc") Then
            Dim doc = app.Documents.Open(file)
            Dim gjzs As String = "济南|Abcdefg|test"
            Dim flag As Boolean = False
            For Each gjz As String In gjzs.split("|")
                app.ActiveWindow.Selection.WholeStory
                With app.ActiveWindow.Selection.Find
                    .HitHighlight(gjz, RGB(255, 255, 0), , , , , , , True)
                End With
                If app.ActiveWindow.Selection.Find.Execute Then flag = True
            Next
            If flag = False  Then
                Doc.close
            Else
                s = s & IIF(s>"", chr(13), "") & file
            End If
        End If
    Next
   
    If s > "" Then
        MessageBox.Show("共计找到包含关键字的文档有" & s.Split(chr(13)).Length & "个,目录如下:" & vbcrlf & s,"关键字文档查找",MessageBoxButtons.OK,MessageBoxIcon.None)
        app.Visible = True
    Else
        MessageBox.Show("没有找到包含关键字的文档","关键字文档查找",MessageBoxButtons.OK,MessageBoxIcon.None)
        app.quit
    End If
   
catch ex As exception
    msgbox(ex.message)
    app.Quit
finally
End try

--  作者:jyh7081
--  发布时间:2018/3/9 22:51:00
--  

这句代码:

MessageBox.Show("共计找到包含关键字的文档有" & s.Split(chr(13)).Length & "个,目录如下:" & vbcrlf & s,"关键字文档查找",MessageBoxButtons.OK,MessageBoxIcon.None)

 

换成文本框显示,每个文件路径分行,怎么改?
e.Form.Controls("TextBox3").text = "共计找到包含关键字的文档有" & s.Split(chr(13)).Length & "个,目录如下:" & vbcrlf & s

 

现在显示这样:

 



此主题相关图片如下:image 1.jpg
按此在新窗口浏览图片

--  作者:有点蓝
--  发布时间:2018/3/9 23:11:00
--  
s = s & IIF(s>"", chr(13), "") & file
改为
s = s & IIF(s>"", vbcrlf , "") & file