我收到以下错误在我的AutoIt脚本:

  

“阵列变量标格式错误”。

和它被抛出在这条线:Local $allDirs[$countDirs]

Func archiveDir($dir)

    ; Get all the files under the current dir
    $allOfDir = _FileListToArray($dir)
    Local $countDirs = 0
    Local $countFiles = 0

    $imax = UBound($allOfDir)
    For $i = 0 to $imax - 1
        If StringInStr(FileGetAttrib($allOfDir[$i]),"D") Then
            $countDirs = $countDirs + 1
        Else
            $countFiles = $countFiles + 1
        EndIf   
    Next

    Local $allDirs[$countDirs]
    Local $allFiles[$countFiles]

任何想法?

有帮助吗?

解决方案

我猜你要么没有任何子目录或代码中查找它们不能正常工作。所以,你的代码试图宣布0长度的数组。

你在哪里得到错误的行前加入这一行权。

MsgBox(0, "Value of $countDirs", $countDirs)

更新

_FileListToArray只返回文件/文件夹名称,而不是完整的路径。因为它没有找到文件/文件夹FileGetAttrib的通话将返回一个空字符串。修改您的If包含的文件名父路径。

If StringInStr(FileGetAttrib($dir & "\" & $allOfDir[$i]), "D") Then

其他提示

运行你的代码,我只得到一个错误,如果$ countDirs或$ countFiles等于0。您应该尝试宣告你的阵列时使用这些值之前,检查此。

此外,快速注意到,您的for循环从0开始......在AuotIt 0指数的数组保存数组中的项目数。你可以不喜欢这样,而不是:

For $i = 1 to $allOfDir[0]
    If StringInStr(FileGetAttrib($allOfDir[$i]), "D") Then
        $countDirs+=1
    Else
       $countFiles+=1
    EndIf
Next

If ($coundDirs > 0) Then
   Local $allDirs[$countDirs]
   ; do whatever else you need to do here.
EndIf

If ($countFiles > 0) Then
   Local $allFiles[$countFiles]
   ; do whatever else you need to do here.
EndIf
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top