Jump to content

Problem with For Loop.


AwAke
 Share

Recommended Posts

Ok with this script, the for loop works;

#Include <File.au3>
#Include <Array.au3>
#Include <Zip.au3>

Global $Drive, $Files, $File, $Zip, $Path, $count = 1
$Zip = _Zip_Create(@DesktopDir & "ziptest.zip")
;If @Error Then MsgBox(0, "", "Create")
_Check()

Func _Check()
    $Drive = DriveGetDrive("REMOVABLE")
    $Files = _FileListToArray($Drive[2])
    For $i = 1 To $Files[0]
        $Path = $Drive[2]&"\"&$Files[$i]
        If @Error = 1 Then Exit
        MsgBox(0, "", $Files[$i])
        $Check = FileGetAttrib($Path)
        If $Check = "D" Then
            ;_Zip_AddFolder($Zip, $Path, 4)
        ElseIf $Check = "A" Then
           ; __Zip_AddFile($Zip, $Path)
        EndIf
    Next
EndFuncoÝ÷ Øz0z÷«ò+zj/^r¦z{_®­ëp¡û§rبƬ²ç!jëh×6Func _Check()
    $Drive = DriveGetDrive("REMOVABLE")
    $Files = _FileListToArray($Drive[2])
    For $i = 1 To $Files[0]
        $Path = $Drive[2]&"\"&$Files[$i]
        If @Error = 1 Then Exit
        MsgBox(0, "", $Files[$i])
        $Check = FileGetAttrib($Path)
        If $Check = "D" Then
            _Zip_AddFolder($Zip, $Path, 4)
        ElseIf $Check = "A" Then
            _Zip_AddFile($Zip, $Path)
        EndIf
    Next
EndFunc

Then after the first run through the loop in which case its adds the first file to the zip, on the second run it exits with the error -

$Path = $Drive[2]&"\"&$Files[$i]

$Path = $Drive[2]&"\"&$Files^ ERROR

I dont see what it is :| as it works with the first script posted. So perhaps its something with the _zip functions?

Link to comment
Share on other sites

Firstly what is the error?

Secondly, I would look at what the zip functions are doing to $path since it is used it the loop. I like to use ConsleWrite to see what is going on in SciTe. If the path becomes corrupt and you try and use it, this could cause an error.

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Link to comment
Share on other sites

Firstly what is the error?

Secondly, I would look at what the zip functions are doing to $path since it is used it the loop. I like to use ConsleWrite to see what is going on in SciTe. If the path becomes corrupt and you try and use it, this could cause an error.

Im not quite sure what you ment by it so I threw a few consolewrites($path) in there to see what happens to the path along the process however it just stays the same;

Func _Check()
    $Drive = DriveGetDrive("REMOVABLE")
    $Files = _FileListToArray($Drive[2])
    For $i = 1 To $Files[0]
        $Path = $Drive[2]&"\"&$Files[$i]
        If @Error = 1 Then Exit
        ConsoleWrite($Path & @CRLF)
        MsgBox(0, "", $Files[$i])
        $Check = FileGetAttrib($Path)
        If $Check = "D" Then
            _Zip_AddFolder($Zip, $Path, 4)
            ConsoleWrite($path & @CRLF)
        ElseIf $Check = "A" Then
            _Zip_AddFile($Zip, $Path)
            ConsoleWrite($path & @CRLF)
        EndIf
    Next
EndFunc

You see then in the lower box;

i:\FolderName1

i:\FolderName1

C:\Documents and Settings\George Quarton\Desktop\AutoIt\PenDriveBackup.au3 (14) : ==> Subscript used with non-Array variable.:

$Path = $Drive[2]&"\"&$Files[$i]

$Path = $Drive[2]&"\"&$Files^ ERROR

:/ Im quite confused so sorry if I acted differently than as suggested.

Link to comment
Share on other sites

Don't do MsgBox(0, "", $Files[$i]), use _ArrayDisplay()

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Link to comment
Share on other sites

The MsgBox was used as a sort of error testing. It has no relevance as the script still exits on the second run of the loop with the error;

>"C:\Program Files\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Documents and Settings\George Quarton\Desktop\AutoIt\PenDriveBackup.au3"

i:\FolderName1

i:\FolderName1

C:\Documents and Settings\George Quarton\Desktop\AutoIt\PenDriveBackup.au3 (14) : ==> Subscript used with non-Array variable.:

$Path = $Drive[2]&"\"&$Files[$i]

$Path = $Drive[2]&"\"&$Files^ ERROR

Thank you for your help though, I appreciate it greatly :)

*EDIT - Changed folder names :/

Edited by AwAke
Link to comment
Share on other sites

Hard to see without seeing the rest of the code. Are you using a var called Drive or Files anywhere else? Put Local in front of them in the declaration.

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Link to comment
Share on other sites

No the whole code is above in my first post however ill repost it for yourself in hope I can get this to work :)

#Include <File.au3>
#Include <Array.au3>
#Include <Zip.au3>

Global $Drive, $Files, $File, $Zip, $Path, $count = 1
$Zip = _Zip_Create(@DesktopDir & "ziptest.zip")
;If @Error Then MsgBox(0, "", "Create")
_Check()

Func _Check()
    $Drive = DriveGetDrive("REMOVABLE")
    $Files = _FileListToArray($Drive[2])
    For $i = 1 To $Files[0]
        $Path = $Drive[2]&"\"&$Files[$i]
        If $Files[$i] = "" Then ContinueLoop
        ConsoleWrite($Path & @CRLF)
        ;MsgBox(0, "", $Files[$i])
        $Check = FileGetAttrib($Path)
        If $Check = "D" Then
            _Zip_AddFolder($Zip, $Path, 4)
            ConsoleWrite($path & @CRLF)
        ElseIf $Check = "A" Then
            _Zip_AddFile($Zip, $Path)
            ConsoleWrite($path & @CRLF)
        EndIf
    Next
EndFunc

So the answer to your question is; No the variables named Files and Drive isnt declared anywhere else.

Edited by AwAke
Link to comment
Share on other sites

The only thing I can think of is in the declaration "Global $Drive, $Files, $File, $Zip, $Path, $count = 1"

Maybe it is making $Drive and what not a int. Try and declare your Arrays separate from everything else.

The error message Subscript used with non-Array variable suggest to me that it thinks you are trying to use a var as an array that is not but I can't see anything wrong with ur code.

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Link to comment
Share on other sites

Ok thanks alot :) it now works, I changed the declarations. I didnt think that would cause the problem, I cant thank you enough. My code is now;

#Include <File.au3>
#Include <Array.au3>
#Include <Zip.au3>

Global $zip, $Path
$Zip = _Zip_Create(@DesktopDir & "ziptest.zip")
;If @Error Then MsgBox(0, "", "Create")
_Check()

Func _Check()
    Local $Drive, $Files, $File
    $Drive = DriveGetDrive("REMOVABLE")
    $Files = _FileListToArray($Drive[2])
    For $i = 1 To $Files[0]
        $Path = $Drive[2]&"\"&$Files[$i]
        ConsoleWrite($Path & @CRLF)
        $Check = FileGetAttrib($Path)
        If $Check = "D" Then
            _Zip_AddFolder($Zip, $Path, 4)
            ConsoleWrite("Folder Added "&$Path & @CRLF)
        ElseIf $Check = "A" Then
            _Zip_AddFile($Zip, $Path)
            ConsoleWrite("File Added "&$Path & @CRLF)
        EndIf
    Next
EndFunc
Link to comment
Share on other sites

No probs, glad it works :)

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...