Sign in to follow this  
Followers 0
TheCuz

Function Error

15 posts in this topic

Hello,

I am trying to make a script that runs at 3am in the morning and moves some file right away, but also has to see if some files are older than 10 days old and move them to another directory. I know that there is only one function that is used, but there will be three functions total that do a file date check to see if the files in the three directories are old enough to move. This is just a test script before I go any further.

I am getting an error message that says: Subscript used with non-Array variable.

The line it errors on is:

$mfiledate = $mgetdate[0] & "/" & $mgetdate[1] & "/" & $mgetdate[2]

Any help would be much apperciated :)

Thnkx!!

#include <Date.au3>

$mff = FileFindFirstFile("d:\folder1\*.txt")

While 1

    If (@HOUR = 03) AND (@MIN = 00) Then

    FileMove("d:\folder3\*.txt", "d:\folder2", 1)

    For $i = 1 to 3

        $ret = Call("xfr" & $i)

    Next

    Sleep(30000)
WEnd

Func xfr1()
While 1

    $gmff = FileFindNextFile($mff)
    If @error Then ExitLoop

    $mgetdate = FileGetTime($gmff, 0, 0)
    $mfiledate = $mgetdate[0] & "/" & $mgetdate[1] & "/" & $mgetdate[2]
    $mdatediff = _DateDiff('D', $mfiledate, _NowCalcDate())

    If $mdatediff < 10 Then

            FileMove($gmff, "d:\folder3\*.txt", 1)

    EndIf
WEnd
FileClose($mff)
EndFunc

[font="Verdana"]People who say it cannot be done should not interrupt those who are doing it. - George Benard Shaw[/font]

Share this post


Link to post
Share on other sites



Just noticed a couple of things, here is the revised code :)

#include <Date.au3>

$mff = FileFindFirstFile("d:\folder1\*.txt")

While 1

;If (@HOUR = 03) AND (@MIN = 00) Then

    FileMove("d:\folder3\*.txt", "d:\folder2", 1)

    For $i = 1 to 3

        $ret = Call("xfr" & $i)

    Next

;EndIf

    Sleep(30000)
WEnd

Func xfr1()
While 1

    $gmff = FileFindNextFile($mff)
    If @error Then ExitLoop

    $mgetdate = FileGetTime($gmff, 0, 0)
    $mfiledate = $mgetdate[0] & "/" & $mgetdate[1] & "/" & $mgetdate[2]
    $mdatediff = _DateDiff('D', $mfiledate, _NowCalcDate())

    If $mdatediff < 10 Then

            FileMove($gmff, "d:\folder3\*.txt", 1)

    EndIf
WEnd
FileClose($mff)
EndFunc

[font="Verdana"]People who say it cannot be done should not interrupt those who are doing it. - George Benard Shaw[/font]

Share this post


Link to post
Share on other sites

this isnt doing much

$ret = Call("xfr" & $i)

maybe

$ret = xfr()

if you want to use the "$i" then

$ret = xfr($i)

however you would need to fix the function to make use of that "$i"

dunno

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

I was just going off of the example of the script in the help file using Call("xfr" & $i) to step through each of the functions so that after it checks the first dir of files that then it would go back to the For statement to continue on to the next Func which then checks the second dir and so forth.

After looking at it, it looks like it would need a Step 1 in order to go from the first Func xfr1 then to xfr2 and so forth.

But can you use an array inside a function? From the error that it gave me, it seems as though you can't do that. Is this true? If so I will have to think up of plan B.

Thanks for looking at it Valuater :)


[font="Verdana"]People who say it cannot be done should not interrupt those who are doing it. - George Benard Shaw[/font]

Share this post


Link to post
Share on other sites

here is a simplified version of what you wanted ( i think )

For $x = 1 to 3
    Call("Test" & $x)
    Sleep(500)
Next

Func Test1()
    MsgBox(4096, "#1", "Hello", 2)
EndFunc

Func Test2()
    MsgBox(4096, "#2", "Hello", 2)
EndFunc

Func Test3()
    MsgBox(4096, "#3", "Hello", 2)
EndFunc

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

Yeah, pretty close. The way that I was thinking how this program would work is that when it hits the For statement, that it would call the first function that would need to be run. That first function would then go to the folder and look for files that are older than 10 days and move them to an archive directory. After that function is done, it would go back to the For statement to see which function needed to run next. Then that function would do the same thing to a different folder.

Am I going about this in the wrong way? Also, is it a limitation of AuoIT to not allow arrays to be run within a function?

Thanks for the help Valuater, it is much appreciated. :)


[font="Verdana"]People who say it cannot be done should not interrupt those who are doing it. - George Benard Shaw[/font]

Share this post


Link to post
Share on other sites

Ok, after some looking into this, it looks like FileGetTime doesn't like a variable for the file name. After just trying the code below, it doesn't want to do this either.

Any ideas as to why?

#include <Date.au3>


$mff = FileFindFirstFile("d:\folder1\*.txt")

$mgd = FileGetTime($mff, 0, 0)

    MsgBox(4096, "Test1", $mgd[1])

Attached is a screenshot of the error message.


[font="Verdana"]People who say it cannot be done should not interrupt those who are doing it. - George Benard Shaw[/font]

Share this post


Link to post
Share on other sites

Here is the latest of weirdness for the array problem. When I run this code, it comes up in the message box with the year for both . and .. but as soon as it comes to a real file (test.txt) it chokes giving me a "Subscript used with non-Array variable."......so who is the genius that is going to figure this one out :)

Is this a bug???

Here is the code:

#include <Date.au3>

$search = FileFindFirstFile("d:\folder1\*.*")

If $search = -1 Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf

While 1
    
    $kstp = FileFindNextFile($search)
    MsgBox(4096, "Find File", $kstp)

    $mgd = FileGetTime($kstp, 0, 0)
    
    $kstpdate = $mgd[0]
    
    MsgBox(4096, "Test1", $kstpdate)
    
WEnd
FileClose($search)

Please help/advise on this problem.

Thnkx :(


[font="Verdana"]People who say it cannot be done should not interrupt those who are doing it. - George Benard Shaw[/font]

Share this post


Link to post
Share on other sites

Here is the latest of weirdness for the array problem. When I run this code, it comes up in the message box with the year for both . and .. but as soon as it comes to a real file (test.txt) it chokes giving me a "Subscript used with non-Array variable."......so who is the genius that is going to figure this one out :)

Is this a bug???

Here is the code:

Please help/advise on this problem.

Thnkx :(

nah.... user error .... try: $mgd = FileGetTime("d:\folder1\" & $kstp, 0, 0)


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Thaks for the feedback JdeB, but with using what you had suggested, it errors out even earlier than before. It used to give the date for . and .., but now it only gives the date for . and shows the file name for .. but no date before it gives me the "Subscript used with non-Array variable."

Any other ideas?:)

Here is what I tested -

#include <Date.au3>

$search = FileFindFirstFile("d:\folder1\*.*")

If $search = -1 Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf

While 1
    
    $kstp = FileFindNextFile($search)
    MsgBox(4096, "Find File", $kstp)

    $mgd = FileGetTime("d:\folder1\" & $kstp, 0, 0) 
    
    $kstpdate = $mgd[0]
    
    MsgBox(4096, "Test1", $kstpdate)
    
WEnd
FileClose($search)

What I don't understand is why is it able to give me the date for . and .. but not a real file?

Thanks for the help.


[font="Verdana"]People who say it cannot be done should not interrupt those who are doing it. - George Benard Shaw[/font]

Share this post


Link to post
Share on other sites

Thaks for the feedback JdeB, but with using what you had suggested, it errors out even earlier than before. It used to give the date for . and .., but now it only gives the date for . and shows the file name for .. but no date before it gives me the "Subscript used with non-Array variable."

Any other ideas?:)

Here is what I tested -

#include <Date.au3>

$search = FileFindFirstFile("d:\folder1\*.*")

If $search = -1 Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf

While 1
    
    $kstp = FileFindNextFile($search)
    MsgBox(4096, "Find File", $kstp)

    $mgd = FileGetTime("d:\folder1\" & $kstp, 0, 0) 
    
    $kstpdate = $mgd[0]
    
    MsgBox(4096, "Test1", $kstpdate)
    
WEnd
FileClose($search)

What I don't understand is why is it able to give me the date for . and .. but not a real file?

Thanks for the help.

Stands to reason that it would error if it isn't an array, try this:
#include <Date.au3>

$search = FileFindFirstFile("d:\folder1\*.*")

If $search = -1 Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf

While 1
    
    $kstp = FileFindNextFile($search)
    MsgBox(4096, "Find File", $kstp)

    $mgd = FileGetTime("d:\folder1\" & $kstp, 0, 0)
    If IsArray($mgd) Then
        $kstpdate = $mgd[0]
        MsgBox(4096, "Test1", $kstpdate)
    EndIf
WEnd
FileClose($search)

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Thaks for the feedback JdeB, but with using what you had suggested, it errors out even earlier than before. It used to give the date for . and .., but now it only gives the date for . and shows the file name for .. but no date before it gives me the "Subscript used with non-Array variable."

Any other ideas?:)

What I don't understand is why is it able to give me the date for . and .. but not a real file?

Thanks for the help.

this works fine for me:

#include <Date.au3>

$search = FileFindFirstFile("c:\temp\*.*")

If $search = -1 Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf

While 1
    $kstp = FileFindNextFile($search)
    $fullFile = "c:\temp\" & $kstp
    $mgd = FileGetTime("c:\temp\" & $kstp, 0, 0) 
    If Not @error Then 
        $kstpdate = $mgd[0]
        MsgBox(4096, "test1", $fullFile & ":" & $kstpdate)
    Else
        MsgBox(4096, "test1 error", $fullFile & ":cannot get date ...")
    EndIf
    
WEnd
FileClose($search)

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Thank you SmOke_N and JdeB for all of your help. Both of your scripts worked well.

One thing that I found out (which may or may not be of interest) is that when I changed

$search = FileFindFirstFile("d:\folder1\*.*)
from using *.* to *.txt, my original script starting to work with no errors.

Any idea on why this would get rid of the non-array variable problem that was happening? It seems weird to me that it would work one way and not the other.


[font="Verdana"]People who say it cannot be done should not interrupt those who are doing it. - George Benard Shaw[/font]

Share this post


Link to post
Share on other sites

Thank you SmOke_N and JdeB for all of your help. Both of your scripts worked well.

One thing that I found out (which may or may not be of interest) is that when I changed

$search = FileFindFirstFile("d:\folder1\*.*)
from using *.* to *.txt, my original script starting to work with no errors.

Any idea on why this would get rid of the non-array variable problem that was happening? It seems weird to me that it would work one way and not the other.

Now you are doing it specific, where as before you were looking for anything in the folder. Maybe some of those folders/files don't have the standard date stamp as your .txt files do. Just a guess.

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

For this project they are all going to be the same extension, but I might need this same thing for other things that have multiple files with different extensions and would like to use a wildcard for the extension to search the whole directory.

I am curious as to why this code works:

#include <Date.au3>

$search = FileFindFirstFile("d:\folder1\*.txt")

If $search = -1 Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf

While 1
    
    $kstp = FileFindNextFile($search)
    If @error Then ExitLoop
    
    MsgBox(4096, "Find File", $kstp)

    $mgd = FileGetTime("d:\folder1\" & $kstp, 0, 0)
   ;If IsArray($mgd) Then
        $kstpdate = $mgd[0]
        MsgBox(4096, "Test1", $kstpdate)
   ;EndIf
WEnd
FileClose($search)

But when I run this one, it gives the year for . and .. but after that it stops the script with a non-array varaible error:( I commented out the part that made it work when I use *.*)

#include <Date.au3>

$search = FileFindFirstFile("d:\folder1\*.*")

If $search = -1 Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf

While 1
    
    $kstp = FileFindNextFile($search)
    If @error Then ExitLoop
    
    MsgBox(4096, "Find File", $kstp)

    $mgd = FileGetTime("d:\folder1\" & $kstp, 0, 0)
   ;If IsArray($mgd) Then
        $kstpdate = $mgd[0]
        MsgBox(4096, "Test1", $kstpdate)
   ;EndIf
WEnd
FileClose($search)

I am just trying to understand why one way works but the other doesn't so I know what to look for when doing this kind stuff later on and can figure out what to do and not to do.

Thanks for the help SmOke_N :)


[font="Verdana"]People who say it cannot be done should not interrupt those who are doing it. - George Benard Shaw[/font]

Share this post


Link to post
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
Sign in to follow this  
Followers 0