Jump to content

How Delete an object and have it not declared


Recommended Posts

I found this a while back and have used it in a backup script and has work great at doing a complete directory and subdirectories file list. The problem now is that I want to try it to backup a few network devices and I am using a for next statement that goes through an array of about 10 devices to get the file list from and then check to make sure the file exists on the backup drive and if not copy it. The problem I have is that there is an If statement that looks to see if an object was declared and this is what is giving me the hiccup in this script. The first device is fine but then when it runs for the second device it does not go through the reinitialization of the object and gives an error:

C:\Documents and Settings\mchartier\My Documents\Scripts\backuptesting.au3 (49) : ==> Variable must be of type "Object".:

For $Subfolder in $rootFolder.SubFolders

For $Subfolder in $rootFolder^ ERROR

Here is what I have in that function I have tried to close the object and also change from IsDeclared to IsObj after closing the object. With the IsObj it seems to be in a complete loop it never returns the list.

Func _AdvancedFileListToArray($sPath, $rootFolder = '')
    If NOT IsDeclared("objFSO") Then
        Global $objFSO = ObjCreate("Scripting.FileSystemObject")
        $AFLTfilecount = DirGetSize ($sPath,1)
        Global $objArray[$AFLTfilecount[1] + 1]
        $rootFolder = $objFSO.GetFolder($sPath)
        For $objFile in $rootFolder.Files
            $objArray[$objArray[0] + 1] = $sPath & "\" & $objFile.Name
            $objArray[0] += 1
        Next
    EndIf
                       
    For $Subfolder in $rootFolder.SubFolders
        $objFolder = $objFSO.GetFolder($Subfolder.Path)
        For $objFile in $objFolder.Files
            $objArray[$objArray[0] + 1] = $Subfolder.Path & "\" & $objFile.Name
            $objArray[0] += 1
        Next
        _AdvancedFileListToArray($sPath, $Subfolder)
    Next
    Return $objArray
    $objFSO.close
EndFunc

I do not remember exactly where or who I got the function from.

Link to comment
Share on other sites

I would avoid using that function, instead use the RecursiveFileSearch function at the bottom of post #1.

#include <Array.au3>

;Find all files in desired folder recursively

$result = RecursiveFileSearch(@DesktopDir & "\Test", "", "", 1)

_ArrayDisplay($result)

Link to comment
Share on other sites

I have tried that now, on one of the devices there are over 6000 files returned and for some reason when I view the array anything from 3998 on the value is in the same column as the row number

_ArrayDisplay has a limit of 4000 items, which I think is a ListView limitation.

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...