redapple2008 发表于 2009-9-6 13:50:21

文件拷贝问题

看看下面的代码错在哪里了:
$Source = "F:\水木方XP3英文版.iso" ; directory to copy (2.7GB)
$Destination = "e:\"; copied to here

$FLTAR = _FileListToArrayR($Source, "",0,0, 1)
MsgBox(0,"",$FLTAR)
ProgressOn("Copying...", "Copy Progress")
For $i = 1 To $FLTAR
    If StringInStr(FileGetAttrib($FLTAR[$i]), "D") Then
      DirCreate($Destination & StringReplace($FLTAR[$i], $Source, ""))
    Else   
      FileCopy($FLTAR[$i], $Destination & StringReplace($FLTAR[$i], $Source, ""), 9)
    EndIf
    ProgressSet((100/$FLTAR) * $i, "Copied: " & StringMid($FLTAR[$i], StringInStr($FLTAR[$i], "\", 0, -1) + 1)&@CRLF & "Completed: " & Round((100/$FLTAR) * $i) & "%")
Next   


Func _FileListToArrayR($sPath, $sExFilter = "", $iFlag = 0, $iRecurse = 0, $iDepth = 0)
    Local $hSearch, $sFile, $sRxpFilter, $asFileList
    If Not $iDepth Then
      Global $sHoldFiles = ''
      If Not FileExists($sPath) Then Return SetError(1, 1, "")
      If StringRegExp($sExFilter, "[\\/<> :* ?]", 0) Then Return SetError(2, 2, "")
      If Not ($iFlag = 0 Or $iFlag = 1 Or $iFlag = 2) Then Return SetError(3, 3, "")
      If Not ($iRecurse = 0 Or $iRecurse = 1) Then Return SetError(4, 4, "")
    EndIf
    If StringRight($sPath, 1) <> "\" Then $sPath &= "\"
    If $sExFilter = "" Then
      $sRxpFilter = "."
    Else
      $sRxpFilter = "(?i)\.(" & $sExFilter & ")"
    EndIf
    $hSearch = FileFindFirstFile($sPath & "*")
    If $hSearch = -1 Then Return SetError(5, 5, "")
    While 1
      $sFile = FileFindNextFile($hSearch)
      If @error Then ExitLoop
      If StringInStr(FileGetAttrib($sPath & $sFile), "D") Then
            If Not $iRecurse And $iFlag = 1 Then ContinueLoop
            If $iRecurse Then
                _FileListToArrayR($sPath & $sFile, $sExFilter, $iFlag, $iRecurse, $iDepth + 1)
                If $iFlag <> 1 Then $sHoldFiles &= $sPath & $sFile & "|"
            Else
                $sHoldFiles &= $sPath & $sFile & "|"
            EndIf
      ElseIf StringRegExp($sFile, $sRxpFilter, 0) And $iFlag <> 2 Then
            $sHoldFiles &= $sPath & $sFile & "|"
      EndIf
    WEnd
    FileClose($hSearch)
    If Not $iDepth Then
      $asFileList = StringSplit(StringTrimRight($sHoldFiles, 1), "|")
      $sHoldFiles = ""
      Return $asFileList
    EndIf
EndFunc   ;==>_FileListToArrayR

redapple2008 发表于 2009-9-6 19:14:59

怎么没有高手出来说一下呀?

顽固不化 发表于 2009-9-6 21:07:32

错误描述不清楚。

redapple2008 发表于 2009-9-6 21:12:52

$FLTAR
不是有效的数组变量.

KiwiCsj 发表于 2009-9-6 21:32:33

看看下面的代码错在哪里了:
$Source = "F:\水木方XP3英文版.iso" ; directory to copy (2.7GB)
$Destination = "e:\"; copied to here

$FLTAR = _FileListToArrayR($Source, "",0,0, 1)
MsgBox(0,"",$FLTAR) ...
redapple2008 发表于 2009-9-6 13:50 http://www.autoitx.com/images/common/back.gif


_FileListToArrayR($sPath, $sExFilter = "", $iFlag = 0, $iRecurse = 0, $iDepth = 0)
这个函数中说明白了,$iDepth = 0 则拆分为数组返回,否则不拆分,直接返回以|间隔的字符串,所以你这个例子中的调用_FileListToArrayR 的方法中,返回供$FLTAR 这个变量得到的就是一个字符串罢了,而在后续的利用中,你默认它为数组,所以报错。

请根据实际需要调整使用。

redapple2008 发表于 2009-9-6 22:46:42




_FileListToArrayR($sPath, $sExFilter = "", $iFlag = 0, $iRecurse = 0, $iDepth = 0)
这个函数中说明白了,$iDepth = 0 则拆分为数组返回,否则不拆分,直接返回以|间隔的字符串,所以你这个例子中的调用_ ...
KiwiCsj 发表于 2009-9-6 21:32 http://www.autoitx.com/images/common/back.gif
还是没有修改成功.

redapple2008 发表于 2009-9-7 21:50:01

看来没有人理了?

redapple2008 发表于 2009-9-8 18:34:21

还是没有修改成功.

KiwiCsj 发表于 2009-9-8 21:28:31

在不在acn 的Q群里?找我kiwicsj.(123群我都在)
把要用的文件打包过来,我给你看一下问题出在哪里。

redapple2008 发表于 2009-9-9 21:48:09

在不在acn 的Q群里?找我kiwicsj.(123群我都在)
把要用的文件打包过来,我给你看一下问题出在哪里。
KiwiCsj 发表于 2009-9-8 21:28 http://www.autoitx.com/images/common/back.gif
就是这段代码,没有文件,只要执行正确就行了。

afan 发表于 2009-9-10 00:15:25

那个函数貌似是针对文件夹的,你丢个文件给它就会造成数组错误

afan 发表于 2009-9-10 02:37:17

而且对于单个文件,此函数及进度条均无意义

redapple2008 发表于 2009-9-12 08:26:57

就是这段代码,没有文件,只要执行正确就行了。
页: [1]
查看完整版本: 文件拷贝问题