以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  ftp重命名后文件路径  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=144210)

--  作者:cd_tdh
--  发布时间:2019/12/13 14:50:00
--  ftp重命名后文件路径

老师,用ftp上传文件成功后,重命名,重命名后的文件路径怎么修改呢?

Dim dlg As New OpenFileDialog \'定义一个新的SaveFileDialog
dlg.MultiSelect = True
dlg.Filter= "Pdf文件|*.pdf|Word文件|*.doc|Rar文件|*.rar" \'设置筛选器
If dlg.showDialog = DialogResult.Ok Then \'如果用户单击了确定按钮
    Dim ftp1 As new  ftpclient
    ftp1.host="
    ftp1.Account = "
    ftp1.password = "
    Dim r As Row = Tables("公司制度管理").Current
    Dim ls = r.DataRow.Lines("路径")
    For Each f As String In dlg.FileNames
                Dim file = "/公司制度/" & filesys.GetName(f)
                If ftp1.DirExists("/公司制度/") = False Then
                    ftp1.MakeDir("/公司制度/")
                End If
        Dim Result As DialogResult
        If ftp1.FileExists(file) Then
            Result = MessageBox.Show("文件已经存在,是否覆盖?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
        End If
        If result = Nothing OrElse result = DialogResult.Yes Then
            If  ftp1.Upload(f,file,True) = True Then
                If ls.contains(file) = False Then
                    ls.add(file)
                End If
                ftp1.Rename("/公司制度/" & filesys.GetName(f), "/公司制度" & "/" & Date.Today & filesys.GetName(f))  \'重命名文件成功!

            Else
                MessageBox.Show( f & "上传失败" ,"提示" ,MessageBoxButtons.OK,MessageBoxIcon.Question)
            End If
        End If

    Next
    r.DataRow.lines("路径") = ls
    ftp1.Close
End If


--  作者:有点蓝
--  发布时间:2019/12/13 16:04:00
--  
为什么不直接使用新名称上传,而上传后再改名,多此一举
--  作者:cd_tdh
--  发布时间:2019/12/13 16:13:00
--  

明白怎么弄个了

    For Each f As String In dlg.FileNames
                Dim file = "/公司制度/" & Date.Today & filesys.GetName(f)
                If ftp1.DirExists("/公司制度/") = False Then
                    ftp1.MakeDir("/公司制度/")
                End If

[此贴子已经被作者于2019/12/13 16:20:27编辑过]