以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 如何代码可以实现上传所选的目录及目录下的文件 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=179062) |
-- 作者:fvcfox -- 发布时间:2022/8/5 10:21:00 -- 如何代码可以实现上传所选的目录及目录下的文件 请教怎样使用 do while 实现可以上传所选目录下所有的文件夹及文件 Dim tb As Table = Tables("文件管理_Table1") Dim rdid, pid, ri As Integer Dim sfl As String rdid = tb.Current("did") pid = tb.Current("childid") sfl = tb.Current("分类") Dim dlg As New FolderBrowserDialog dlg.ShowNewFolderButton = True If dlg.ShowDialog = DialogResult.Ok Then Syscmd.GridTree.AddChild() Dim mr As Row = tb.Current mr.DataRow.Save mr("扩展名") = "文件夹" Dim dds() As String = dlg.SelectedPath.Split ("\\") Dim dd As String = dds(dds.Length - 1) mr("文件名") = dd mr("分类") = sfl mr("childid") = mr("_Identify") mr("did") = rdid mr("parentid") = pid mr ("单位") = Tables("one").rows(0)("单位") mr ("操作员") = Tables("one").rows(0)("操作员") Dim si As String Dim ii As Integer For Each fl As String In FileSys.GetFiles(dlg.SelectedPath) ii = ii + 1 Syscmd.GridTree.AddSlibing() Dim r As Row = tb.Current r.DataRow.Save r("parentid") = mr("childid") r("childid") = r("_Identify") r("did") = rdid Dim ifo As New FileInfo(fl) Dim ss() As String = ifo.Name.Split(".") Dim ffd As DataRow = tb.DataTable.SQLFind ("文件名=\'" & ss(ss.Length - 2) & "\' and 扩展名=\'." & ss(ss.Length - 1) & "\'and parentid=" & pid) If ffd IsNot Nothing Then \'如果找到的话 MessageBox.Show(ss(ss.Length - 2) & "." & ss(ss.Length - 1) & " 该文件名已经存在") r.Delete tb.DataTable.Save Return End If r("分类") = sfl r("文件名") = ss(ss.Length - 2) r("扩展名") = ifo.Extension Dim i As Integer = ifo.Length If i < 1024 Then si = i & " B" ElseIf 1048576 > i AndAlso i >= 1024 Then si = round2(i / 1024, 2) & " KB" ElseIf 1073741824 > i AndAlso i >= 1048576 Then si = round2(i / 1024 / 1024, 2) & " MB" ElseIf 1099511627776 > i AndAlso i >= 1073741824 Then si = round2(i / 1024 / 1024 / 1024, 2) & " GB" End If r("大小") = si r ("单位") = Tables("one").rows(0)("单位") r ("操作员") = Tables("one").rows(0)("操作员") ShowWaitDialog(New Operation(Function() As Boolean \'等待开始 r.DataRow.SQLInsertFile("fl", fl) \'插入文件 End Function), Nothing) \'等待结束\' Next MessageBox.Show ("已成功上传 " & ii & " 个文件") tb.DataTable.Save End If |
-- 作者:有点蓝 -- 发布时间:2022/8/5 10:25:00 -- 上传到哪里? |
-- 作者:fvcfox -- 发布时间:2022/8/5 10:30:00 -- 是将所选目录及其文件名称写到table,并将文件以二进制上传到"“FL”字段,目前代码只能实现所选目录第一级,不知道怎样现实包括以下的所有文件夹及文件 |
-- 作者:有点蓝 -- 发布时间:2022/8/5 10:57:00 -- 使用递归:http://www.foxtable.com/webhelp/topics/2416.htm 假设函数名称:abc,函数内容 dim dir as string For Each fl As String In FileSys.GetFiles(dir) 对文件的处理 next For Each dir2 As String In FileSys.GetDirectories(dir) 如果有子目录 Functions.Execute("abc",dir2 ) Next 1楼代码改改 …… r ("操作员") = Tables("one").rows(0)("操作员") ShowWaitDialog(New Operation(Function() As Boolean \'等待开始 r.DataRow.SQLInsertFile("fl", fl) \'插入文件 End Function), Nothing) \'等待结束\' Next MessageBox.Show ("已成功上传 " & ii & " 个文件") For Each dir2 As String In FileSys.GetDirectories(dlg.SelectedPath) Functions.Execute("abc",dir2 ) Next tb.DataTable.Save End If |