Sign in to follow this  
Followers 0
ghetek

recursive date match error

14 posts in this topic

Here is the error i get.

Line 18 (File "C:\Documents and Settings\aescalante\Desktop\Work\Recursive Dir Date\New AutoIt v3 Script.au3"):

$recfilelist=_FileListToArray ($recdirlist[$i],"*.",1)

$recfilelist=_FileListToArray (^ ERROR

Error: Array variable has incorrect number of subscripts or subscript dimension range exceeded.

#include <Array.au3>
#include <File.au3>
$inidb=@ScriptDir & "\recdirdate.ini"

$recdirlist=_FldrSearch(IniRead($inidb,"Options","rootdir",""))
For $i=1 to $recdirlist[0] Step 1
        $recfilelist=_FileListToArray ($recdirlist[$i],"*.",1)
        if @error > 0 then
            _ArrayDelete ($recdirlist,$i)
        else
        for $g=1 to $recfilelist[0] step 1
            $currentfiledate=FileGetTime ($recfilelist[$g],IniRead($inidb,"Options","timeparam","2"),0)
            if $currentfiledate[0] =< IniRead($inidb,"Options","year","2000") then
                msgbox(0,"title",$recfilelist[$g] & " is too old!")
            Else
                msgbox(0,"title",$recfilelist[$g] & " is fine.")
            endif
        Next
        Endif
Next




Func _FldrSearch($szRoot, $nFlag = 1 )
    If StringRight($szRoot, 1) <> '\' Then $szRoot &= '\'
    Local $szReturn = '',  $szBuffer = '', $szPathlist = '*', $oRoot = $szRoot & '*'
        $Hfile = FileFindFirstFile ($szRoot &'*')
        If $Hfile >= 0 Then
            $szBuffer = FileFindNextFile ($Hfile)
            While NOT @Error
                If Not StringInStr($szBuffer, '.') Then $szPathlist &= $szRoot & $szBuffer & "\*"
                $szBuffer = FileFindNextFile ($Hfile)
            Wend
            FileClose ($Hfile)
        EndIf
        $szReturn = $szPathList

    If $nFlag = 1 Then
        $szPathList = StringTrimLeft($szPathlist, 1)
        $szRoot = StringLeft($szPathList, StringInStr($szPathlist, '*') -1)
        While 1
            $hFile = FileFindFirstFile ($szRoot & '*')
            If $hFile >= 0 Then
                $szBuffer = FileFindNextFile ($Hfile)
            While NOT @Error
                If Not StringInStr($szBuffer, '.') Then
                    $szPathlist &= $szRoot & $szBuffer & "\*"
                    $szReturn &= $szRoot & $szBuffer & "\*"
                EndIf
                $szBuffer = FileFindNextFile ($Hfile)
            Wend
            FileClose($hFile)
            $szPathList = StringReplace($szPathList, $szRoot, '')
            EndIf
            If $szPathList == '*' Then ExitLoop
            $szPathlist = StringTrimLeft ($szPathlist, 1)
            $szRoot = StringLeft ($szPathlist, StringInStr ($szPathlist, "*") - 1) & "\"
            $szPathlist = StringTrimLeft ($szPathlist, StringInStr ($szPathlist, "*") - 1)
       ;$szPathlist = StringReplace($szPathlist, $szRoot, '',1)
        Wend
    EndIf
    If StringLeft($szReturn, 1) = '*' Then $szReturn = StringTrimLeft($szReturn, 1)
    $szReturn = StringReplace($szReturn, '\\', '\')
    If StringRight($szReturn, 1) = '*' Then $szReturn = StringTrimRight($szReturn,1)
    $szReturn = StringSplit($oRoot & $szReturn,'*')
    If $szReturn = '*' or $szReturn = '' Then Return 0
    _ArraySort($szReturn)
    Return $szReturn
EndFunc ;<==> _FldrSearch($szRoot)

and here is the ini file.

timeparam
0 is date modified
1 is date created
2 is date accessed

[options]
rootdir=C:\Documents and Settings\aescalante\Desktop\Work\
timeparam=2
year=2000

Share this post


Link to post
Share on other sites



Start by finding out the number of elemetns that $recdirlist has. Then write the value of $i in a loop and see when it exeeds it.

And this looks pretty wrong to me...

$recfilelist=_FileListToArray ($recdirlist[$i],"*.",1)

Are you using arrays inside arrays?

Share this post


Link to post
Share on other sites

Start by finding out the number of elemetns that $recdirlist has. Then write the value of $i in a loop and see when it exeeds it.

And this looks pretty wrong to me...

$recfilelist=_FileListToArray ($recdirlist[$i],"*.",1)

Are you using arrays inside arrays?

the initial array, recrirlist will create an array of directories. the second array, recfilelist, will create arrays of all the files within the directories that are reported via the initial arrays, recdirlist.

Share this post


Link to post
Share on other sites

i dont think im exceeding a range, the folder structure that i am using in this test is extremely simple.

Share this post


Link to post
Share on other sites

and here is the ini file.

timeparam
0 is date modified
1 is date created
2 is date accessed

[options]
rootdir=C:\Documents and Settings\aescalante\Desktop\Work\
timeparam=2
year=2000

Im just asknig to make sure but in the INI file is the first 4 lines commented. such as

;timeparam
;0 is date modified
;1 is date created
;2 is date accessed

[options]
rootdir=C:\Documents and Settings\aescalante\Desktop\Work\
timeparam=2
year=2000

Because it is just a comment and not a field to look for right.

Share this post


Link to post
Share on other sites

Im just asknig to make sure but in the INI file is the first 4 lines commented. such as

;timeparam
;0 is date modified
;1 is date created
;2 is date accessed

[options]
rootdir=C:\Documents and Settings\aescalante\Desktop\Work\
timeparam=2
year=2000

Because it is just a comment and not a field to look for right.

didnt think those were necessary in an ini file. but updated it anyway. same issue ):

Share this post


Link to post
Share on other sites

does anybody have any good ideas on getting this working?

Share this post


Link to post
Share on other sites

Try changing your For/Next loops to

For $i=1 to Ubound($recdirlist)-1 Step 1

and

for $g=1 to Ubound($recfilelist)-1 step 1


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

i changed those loops to include ubound. still same issue. here is the full script now.

#include <Array.au3>
#include <File.au3>
$inidb=@ScriptDir & "\recdirdate.ini"

$recdirlist=_FldrSearch(IniRead($inidb,"Options","rootdir",""))
For $i=1 to Ubound($recdirlist)-1 Step 1
        $recfilelist=_FileListToArray ($recdirlist[$i],"*.",1)
        if @error > 0 then
            _ArrayDelete ($recdirlist,$i)
        else
        for $g=1 to Ubound($recfilelist)-1 step 1
            $currentfiledate=FileGetTime ($recfilelist[$g],IniRead($inidb,"Options","timeparam","2"),0)
            if $currentfiledate[0] =< IniRead($inidb,"Options","year","2000") then
                msgbox(0,"title",$recfilelist[$g] & " is too old!")
            Else
                msgbox(0,"title",$recfilelist[$g] & " is fine.")
            endif
        Next
        Endif
Next




Func _FldrSearch($szRoot, $nFlag = 1 )
    If StringRight($szRoot, 1) <> '\' Then $szRoot &= '\'
    Local $szReturn = '',  $szBuffer = '', $szPathlist = '*', $oRoot = $szRoot & '*'
        $Hfile = FileFindFirstFile ($szRoot &'*')
        If $Hfile >= 0 Then
            $szBuffer = FileFindNextFile ($Hfile)
            While NOT @Error
                If Not StringInStr($szBuffer, '.') Then $szPathlist &= $szRoot & $szBuffer & "\*"
                $szBuffer = FileFindNextFile ($Hfile)
            Wend
            FileClose ($Hfile)
        EndIf
        $szReturn = $szPathList

    If $nFlag = 1 Then
        $szPathList = StringTrimLeft($szPathlist, 1)
        $szRoot = StringLeft($szPathList, StringInStr($szPathlist, '*') -1)
        While 1
            $hFile = FileFindFirstFile ($szRoot & '*')
            If $hFile >= 0 Then
                $szBuffer = FileFindNextFile ($Hfile)
            While NOT @Error
                If Not StringInStr($szBuffer, '.') Then
                    $szPathlist &= $szRoot & $szBuffer & "\*"
                    $szReturn &= $szRoot & $szBuffer & "\*"
                EndIf
                $szBuffer = FileFindNextFile ($Hfile)
            Wend
            FileClose($hFile)
            $szPathList = StringReplace($szPathList, $szRoot, '')
            EndIf
            If $szPathList == '*' Then ExitLoop
            $szPathlist = StringTrimLeft ($szPathlist, 1)
            $szRoot = StringLeft ($szPathlist, StringInStr ($szPathlist, "*") - 1) & "\"
            $szPathlist = StringTrimLeft ($szPathlist, StringInStr ($szPathlist, "*") - 1)
       ;$szPathlist = StringReplace($szPathlist, $szRoot, '',1)
        Wend
    EndIf
    If StringLeft($szReturn, 1) = '*' Then $szReturn = StringTrimLeft($szReturn, 1)
    $szReturn = StringReplace($szReturn, '\\', '\')
    If StringRight($szReturn, 1) = '*' Then $szReturn = StringTrimRight($szReturn,1)
    $szReturn = StringSplit($oRoot & $szReturn,'*')
    If $szReturn = '*' or $szReturn = '' Then Return 0
    _ArraySort($szReturn)
    Return $szReturn
EndFunc ;<==> _FldrSearch($szRoot)

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

I just noticed that your Ini file entry contains spaces. That will invariably lead to issues.

Either enclose the Ini entry in Quotes or use FileGetShortName.

$Fldr = $recdirlist=_FldrSearch(FileGetShortName(IniRead($inidb,"Options","rootdir","")))

Or $Fldr = FileGetShortName(IniRead($inidb,"Options","rootdir","")

$recdirlist=_FldrSearch($Fldr)

Edit: You also could have checked that using

If IsArray($recdirlist) Then
Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

Also I think

_ArrayDelete ($recdirlist,$i)

Is going to cause a problem because it's changing the size of the array while you are performing functions on that array. Try commenting that line out and see what happens.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

unfortunately without that line the script will have issues when it hits empty directories.

Perhaps i should take a step back here and explain the situation. I would like to make a script that will recursively look through a directory and delete files that exceed a given date. Does anyone have a more elegant/working solution?

Share this post


Link to post
Share on other sites

unfortunately without that line the script will have issues when it hits empty directories.

Perhaps i should take a step back here and explain the situation. I would like to make a script that will recursively look through a directory and delete files that exceed a given date. Does anyone have a more elegant/working solution?

What happens if you change

_ArrayDelete ($recdirlist,$i)
to
ContinueLoop

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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