以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  [求助]设计一段备份的代码  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=101136)

--  作者:Jacksnfeng
--  发布时间:2017/5/25 16:35:00
--  [求助]设计一段备份的代码
我要设计一个备份功能,所以我用了内部函数backup,代码如下:

If filesys.directoryexists(args0) = False OrElse filesys.directoryexists(args1) = False Then Return Nothing

For Each fns As String In filesys.GetFiles(args0) \'fileNameSource

    Dim fnt As String = args1 & "\\" & filesys.GetName(fns) \'fileNameTarget

    If filesys.FileExists(fnt) = False Then

        output.show("step1")

        filesys.copyfile(fns,fnt)

    Else \'比较修改时间

        Dim fis As new fileinfo(fns) \'fileinfoSource

        Dim fist As Date = fis.lastwritetime \'fileinfoSourceTime

        Dim fit As new fileinfo(fnt) \'fileinfoTarget

        Dim fitt As Date = fit.lastwritetime \'fileinfoTargetTime

        If fitt < fist Then

            filesys.copyfile(fns,fnt,True)

        End If

    End If

Next

\'子文件夹

For Each fns As String In filesys.GetDirectories(args0) \'fileNameSource

dim fnt as string = agrs(1) & fnt.replace(args(0),"")

Functions.Execute(fns,fnt) \'递归调用本身 

next

Return Nothing

需要时就调用 Functions.Execute("backup","p:\\desktop\\Foxtable项目\\备份资料\\source","p:\\desktop\\Foxtable项目\\备份资料\\target")

可是总是出错,求高手完善一下。

另,曾尝试FileSys.CopyDirectory完成此功能,但它没有判断新旧文件编辑时间的功能。源文件夹已删除而目标文件夹还有的文件夹怎样删除?这个功能也没有。

 




--  作者:Jacksnfeng
--  发布时间:2017/5/25 16:45:00
--  
以下代码的问题是第三个参数选false就会出错,如果选true就没事,不知何解:
filesys.copydirectory("p:\\desktop\\Foxtable项目\\备份资料\\source","p:\\desktop\\Foxtable项目\\备份资料\\target",False)
--  作者:有点色
--  发布时间:2017/5/25 17:54:00
--  

If filesys.directoryexists(args(0)) = False OrElse filesys.directoryexists(args(1)) = False Then Return Nothing
For Each fns As String In filesys.GetFiles(args(0)) \'fileNameSource
   
    Dim fnt As String = args(1) & "\\" & filesys.GetName(fns) \'fileNameTarget
   
    If filesys.FileExists(fnt) = False Then
       
        output.show("step1")
       
        filesys.copyfile(fns,fnt)
       
    Else \'比较修改时间
       
        Dim fis As new fileinfo(fns) \'fileinfoSource
       
        Dim fist As Date = fis.lastwritetime \'fileinfoSourceTime
       
        Dim fit As new fileinfo(fnt) \'fileinfoTarget
       
        Dim fitt As Date = fit.lastwritetime \'fileinfoTargetTime
       
        If fitt < fist Then
           
            filesys.copyfile(fns,fnt,True)
           
        End If
       
    End If
   
Next

\'子文件夹
For Each fns As String In filesys.GetDirectories(args(0)) \'fileNameSource
   
    Dim fnt As String = args(1) & fns.replace(args(0),"")
    If FileSys.DirectoryExists(fnt) = False Then
        FileSys.CreateDirectory(fnt)
    End If
    Functions.Execute("backup", fns,fnt) \'递归调用本身
   
Next


Return Nothing