hidoing 发表于 2009-2-19 21:23:00

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

能用批处理实现复制指定时间段的文件吗?
有一个document的文件夹,里面有很多的不同用户建立的文件夹及子文件夹,怎样才能实现把这些文件夹及子文件夹中的2008年建立的文件,移动到另外一个硬盘分区里,要求复制包括文件目录,子目录和2008年建立的所有文件。文件分区格式为ntfs,要求复制文件夹和文件的时候,ntfs权限也跟着复制过来。
请教能否实现?要怎样写批处理?请高手指教!!

sxd 发表于 2009-2-19 22:09:02

www.bathome.cn

hidoing 发表于 2009-2-24 23:38:04

真的没办法吗?

sxd 发表于 2009-2-24 23:56:19

我的意思是请移步至批处理讨论论坛讨论此问题

qingting 发表于 2009-3-19 22:31:26

有个现成的,是在别人的代码上进行修改了的,不是很完善,但是够用了
;===============================================================================
;
;描述:      复制目录下所有文件或文件夹,包括子文件夹.(注:autoit官方版本_FileListToArray不包括搜索子文件夹,也不支持正则表达式)
;
;函数:                copymyFileList($sPath,$dPath,$iFlag=0,$sPathExclude=0,$time=0)
;
;参数:          $sPath=要复制的路径
;                                        $dpath = 目的路径
;                                        $iFlag=3    仅复制修改时间在$time之后的文件
;               $sPathExclude=在路径中要要排除的词语,多个有,分隔
;
;最低版本需求:    autoitv3.2.2.0
;返回值:      
;===============================================================================



Func copymyFileList($sPath, $dPath, $iFlag = 0, $sPathExclude = 0, $time = 0)
        Local $asFileList ,$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 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
;                $asFileList = $asFileList + 1
;                $asFileList = $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 编辑 ]

xrbenbeba 发表于 2009-3-20 00:33:08

楼上的已经足够了
页: [1]
查看完整版本: 能用批处理实现复制指定时间段的文件吗?