Foxtable(狐表)用户栏目专家坐堂 → [求助]文件递归怎样应用


  共有2385人关注过本帖树形打印复制链接

主题:[求助]文件递归怎样应用

帅哥哟,离线,有人找我吗?
jyh7081
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:四尾狐 帖子:962 积分:8505 威望:0 精华:0 注册:2012/10/3 13:25:00
[求助]文件递归怎样应用  发帖心情 Post By: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

 


 回到顶部
帅哥哟,离线,有人找我吗?
jyh7081
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:四尾狐 帖子:962 积分:8505 威望:0 精华:0 注册:2012/10/3 13:25:00
  发帖心情 Post By: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


 回到顶部
帅哥哟,离线,有人找我吗?
jyh7081
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:四尾狐 帖子:962 积分:8505 威望:0 精华:0 注册:2012/10/3 13:25:00
  发帖心情 Post By: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
按此在新窗口浏览图片

 回到顶部