以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  [求助]代码问题  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=83805)

--  作者:pcxjxjhkw
--  发布时间:2016/4/17 14:24:00
--  [求助]代码问题

求老师将下面代码看一下,总是出问题

 

\'\'\'将扫描的档案的路径及文件名写入表中

Dim path As String = Args(0)    \'\'\'路径
Dim dt As DataTable = DataTables("扫描档案")

If FileSys.GetFiles(path).Count > 0 Then
    For Each wj As String In FileSys.GetFiles(path)
        If FileSys.GetName(wj).Contains(".jpg") = True Then  \'\'\'如果是图片文件
            Dim str As String = FileSys.GetParentPath(wj)  \'\'\'文件路径
            Dim wjm As String = FileSys.GetName(wj)   \'\'\'文件名
            Dim n As Integer = dt.Compute("count([文件名])","路径 = \'" & str & "\' And 文件名 = \'" & wjm & "\'")
            If n = 0 Then   \'\'\'如果表中无此文件
                Dim dr As DataRow =  dt.AddNew
                dr("路径") = str
                dr("文件名") = wjm
            End If
        End If
    Next
End If

If FileSys.GetDirectories(path).count > 0 Then
    For Each pth As String In FileSys.GetDirectories(path)   \'\'\'遍历子文件夹,
        If FileSys.GetFiles(pth).Count > 0 Then
            For Each wj As String  In FileSys.GetFiles(pth)   \'\'\'遍历子文件夹下的文件
                If FileSys.GetName(wj).Contains(".jpg") = True Then  \'\'\'如果是图片文件
                    Dim str As String = FileSys.GetParentPath(wj)  \'\'\'文件路径
                    Dim wjm As String = FileSys.GetName(wj)   \'\'\'文件名
                    Dim n As Integer = dt.Compute("count([文件名])","路径 = \'" & str & "\' And 文件名 = \'" & wjm & "\'")
                    If n = 0 Then   \'\'\'如果表中无此文件
                        Dim dr As DataRow =  dt.AddNew
                        dr("路径") = str
                        dr("文件名") = wjm
                    End If
                End If
            Next
        End If
        If FileSys.GetDirectories(pth).Count > 0 Then  \'\'\'如果还有子文件
            Functions.Execute("添加档案")
        End If
    Next
End If
dt.Save
MessageBox.Show("添加档案结束")


--  作者:Hyphen
--  发布时间:2016/4/17 14:44:00
--  
Dim path As String = Args(0)    \'\'\'路径
Dim dt As DataTable = DataTables("扫描档案")

For Each wj As String In FileSys.GetFiles(path)
    If FileSys.GetName(wj).Contains(".jpg") = True Then  \'\'\'如果是图片文件
        Dim str As String = FileSys.GetParentPath(wj)  \'\'\'文件路径
        Dim wjm As String = FileSys.GetName(wj)   \'\'\'文件名
        Dim n As Integer = dt.Compute("count([文件名])","路径 = \'" & str & "\' And 文件名 = \'" & wjm & "\'")
        If n = 0 Then   \'\'\'如果表中无此文件
            Dim dr As DataRow =  dt.AddNew
            dr("路径") = str
            dr("文件名") = wjm
        End If
    End If
Next

For Each pth As String In FileSys.GetDirectories(path)   \'\'\'遍历子文件夹,
    Functions.Execute("添加档案",pth)
Next
-------------------------------
以下2句放到外面调用函数结束后,不要放到函数中
DataTables("扫描档案").Save()  \'原dt.Save
MessageBox.Show("添加档案结束")