以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  文件夹下存在同名文件,出错。  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=74456)

--  作者:yancheng
--  发布时间:2015/9/11 11:55:00
--  文件夹下存在同名文件,出错。
材料,表,DataColChanged事件代码如下:
Select Case e.DataCol.Name
    Case "分类"
        If e.DataRow.IsNull("材料文件") = False Then
            Dim str As String = ""
            For Each file As String In e.DataRow.Lines("材料文件")
                str &= "人机材基础\\材料文件\\" & e.DataRow("分类") & "\\" & FileSys.GetName(file) & vbcrlf
            Next
            e.DataRow("材料文件") = str
        End If
            If e.DataRow.IsNull("材料文件")=False Then
        If FileSys.DirectoryExists(ProjectPath & "Attachments\\人机材基础\\材料文件\\" & e.NewValue) Then
            For Each file As String In e.DataRow.Lines("材料文件")
                FileSys.MoveFile(ProjectPath & "Attachments\\人机材基础\\材料文件\\" & e.oldValue & "\\" & FileSys.GetName(file),ProjectPath & "Attachments\\人机材基础\\材料文件\\" &  e.newValue & "\\" & FileSys.GetName(file))
            Next
        Else
            FileSys.CreateDirectory(ProjectPath & "Attachments\\人机材基础\\材料文件\\" & e.newValue)
            For Each file As String In e.DataRow.Lines("材料文件")
                FileSys.MoveFile(ProjectPath & "Attachments\\人机材基础\\材料文件\\" & e.oldValue & "\\" & FileSys.GetName(file),ProjectPath & "Attachments\\人机材基础\\材料文件\\" &  e.newValue & "\\" & FileSys.GetName(file))
            Next
        End If
    End If

我在对,材料文件,更改:分类,时,如果这个分类下没有相同的文件,就不会出错。代码正常执行。如果更改后的:分类,名的文件夹下,有相同的,同名文件,就会提示。
调用出错误,死机了。
图片点击可在新窗口打开查看此主题相关图片如下:222.jpg
图片点击可在新窗口打开查看

--  作者:大红袍
--  发布时间:2015/9/11 12:01:00
--  

先删除,然后在Move

 

    For Each file As String In e.DataRow.Lines("材料文件")
        Dim nfile As String = ProjectPath & "Attachments\\人机材基础\\材料文件\\" &  e.newValue & "\\" & FileSys.GetName(file)
        If filesys.FileExists(nfile) Then
            FileSys.DeleteFile(nfile,2,2)
        End If
        FileSys.MoveFile(ProjectPath & "Attachments\\人机材基础\\材料文件\\" & e.oldValue & "\\" & FileSys.GetName(file),ProjectPath & "Attachments\\人机材基础\\材料文件\\" &  e.newValue & "\\" & FileSys.GetName(file))
    Next


--  作者:yancheng
--  发布时间:2015/9/11 12:19:00
--  
按你的代码写,可以了。
我想问一下,像这种管理文件。应该用到哪里判断,思路是怎样的?我这样做,会不会以后出现什么问题?
通常的管理文件的思路是怎么样的?

--  作者:yancheng
--  发布时间:2015/9/11 12:21:00
--  
 Dim nfile As String =ProjectPath & "Attachments\\人机材基础\\材料文件\\" &  e.newValue & "\\" & FileSys.GetName(file)
这个代码,为什么不是这样的?不加“”号呢?它不是字符吗?
 Dim nfile As String =“ProjectPath & "Attachments\\人机材基础\\材料文件\\" &  e.newValue & "\\" & FileSys.GetName(file)”

--  作者:大红袍
--  发布时间:2015/9/11 12:27:00
--  

回复3楼,参考

 

http://www.foxtable.com/help/topics/2209.htm

 


--  作者:大红袍
--  发布时间:2015/9/11 12:27:00
--  

回复4楼,参考 http://www.foxtable.com/help/topics/0221.htm