Sign in to follow this  
Followers 0
mnchartier

How Delete an object and have it not declared

6 posts in this topic

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.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Most likely got it here:

http://www.autoitscript.com/forum/index.ph...c=58558&hl=

Its one of least efficient ways of getting a file list to an array. Notice there is error control in the script as it is merely proof-of-concept.

Edited by weaponx

Share this post


Link to post
Share on other sites

Yes that is the posting I got it from. I have been trying to edit the function so that the object gets destroyed after the first device was backed up and go to the next, that is where the error comes from

Share this post


Link to post
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)

Share this post


Link to post
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

Share this post


Link to post
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.

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