找回密码
 加入
搜索
查看: 3109|回复: 5

能用批处理实现复制指定时间段的文件吗?

[复制链接]
发表于 2009-2-19 21:23:00 | 显示全部楼层 |阅读模式
能用批处理实现复制指定时间段的文件吗?
有一个document的文件夹,里面有很多的不同用户建立的文件夹及子文件夹,怎样才能实现把这些文件夹及子文件夹中的2008年建立的文件,移动到另外一个硬盘分区里,要求复制包括文件目录,子目录和2008年建立的所有文件。文件分区格式为ntfs,要求复制文件夹和文件的时候,ntfs权限也跟着复制过来。
请教能否实现?要怎样写批处理?请高手指教!!
发表于 2009-2-19 22:09:02 | 显示全部楼层
 楼主| 发表于 2009-2-24 23:38:04 | 显示全部楼层
真的没办法吗?
发表于 2009-2-24 23:56:19 | 显示全部楼层
我的意思是请移步至批处理讨论论坛讨论此问题
发表于 2009-3-19 22:31:26 | 显示全部楼层
有个现成的,是在别人的代码上进行修改了的,不是很完善,但是够用了
;===============================================================================
;
;  描述:        复制目录下所有文件或文件夹,包括子文件夹.(注:autoit官方版本_FileListToArray不包括搜索子文件夹,也不支持正则表达式)
;
;  函数:                copymyFileList($sPath,$dPath,  $iFlag  =  0,$sPathExclude=0,$time=0)
;
;  参数:          $sPath  =  要复制的路径
;                                        $dpath = 目的路径
;                                        $iFlag=3    仅复制修改时间在$time之后的文件
;                 $sPathExclude  =  在路径中要要排除的词语,多个有,分隔
;
;  最低版本需求:    autoit  v3.2.2.0
;  返回值:      
;===============================================================================



Func copymyFileList($sPath, $dPath, $iFlag = 0, $sPathExclude = 0, $time = 0)
        Local $asFileList[1] ,$Progress_cp_i
        $Progress_cp_i=1
        $asFileList = copymyFileListTemp($asFileList, $sPath, $dPath, $iFlag, $sPathExclude, $time)
        Return $asFileList
EndFunc   ;==>myFileListToArray

Func copymyFileListTemp(ByRef $asFileList, $sPath, $dPath = 0, $iFlag = 0, $sPathExclude = 0, $time = 0)
        Local $hSearch, $sFile
        If Not FileExists($sPath) Then Return SetError(1, 1, "")
        If Not FileExists($dPath) Then Return SetError(2, 2, "")
        If Not ($iFlag = 0 Or $iFlag = 1 Or $iFlag = 2 Or $iFlag = 3) Then Return SetError(3, 3, "")
        $hSearch = FileFindFirstFile($sPath & "\*")
        If $hSearch = -1 Then Return SetError(4, 4, "")

        While 1
                $sFile = FileFindNextFile($hSearch)
                If @error Then
                        SetError(0)
                        ExitLoop
                EndIf
                ;获取文件时间
                If $iFlag = 3 Then
                        $filetime = FileGetTime($sPath & "\" & $sFile,0,1)
                        If Not @error Then
                        If $time > $filetime Then
                                ContinueLoop
                        EndIf
                        EndIf
                EndIf

                If $sPathExclude And StringLen($sPathExclude) > 0 Then $sPathExclude = StringSplit($sPathExclude, ",")
                $bExclude = False
                If IsArray($sPathExclude) Then
                        For $ii = 1 To $sPathExclude[0] Step 1
                                If StringInStr($sPath & "\" & $sFile, $sPathExclude[$ii]) Then
                                        $bExclude = True
                                        ExitLoop
                                EndIf
                        Next
                EndIf
                If $bExclude Then ContinueLoop

                Select
                        Case StringInStr(FileGetAttrib($sPath & "\" & $sFile), "D")
                                Select
                                        Case $iFlag = 1
                                                copymyFileListTemp($asFileList, $sPath & "\" & $sFile, $dPath, $iFlag, $sPathExclude, $time)
                                                ContinueLoop
                                        Case $iFlag = 2 Or $iFlag = 0 Or $iFlag = 3
                                                copymyFileListTemp($asFileList, $sPath & "\" & $sFile, $dPath & "\" & $sFile, $iFlag, $sPathExclude, $time)
                                EndSelect

                        Case Not StringInStr(FileGetAttrib($sPath & "\" & $sFile), "D")
                                If $iFlag = 2 Then ContinueLoop
                                ;If $rPath And Not StringRegExp($sPath & "\" & $sFile, $rPath, 0) Then ContinueLoop
                EndSelect

;                ReDim $asFileList[UBound($asFileList) + 1]
;                $asFileList[0] = $asFileList[0] + 1
;                $asFileList[UBound($asFileList) - 1] = $sPath & "\" & $sFile
                FileCopy ( $sPath & "\" & $sFile, $dPath & "\" & $sFile, 8 )
                ;ProgressCopy( $sPath & "\" & $sFile, $dPath & "\" & $sFile, 8 )
               
        WEnd
        FileClose($hSearch)
        Return True
EndFunc

[ 本帖最后由 qingting 于 2009-3-19 22:32 编辑 ]
发表于 2009-3-20 00:33:08 | 显示全部楼层
楼上的已经足够了
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-9-23 06:34 , Processed in 0.079306 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表