|
发表于 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 编辑 ] |
|