Jump to content

Recommended Posts

Posted (edited)

I found a problem.

On this line:

$aFileList = _FileListToArray($FilePath, "*", $FLTA_FILESFOLDERS, True)

$FilePath = C:\$WINDOWS.~BT

$aFileList = blank (nothing is in the array)

There are no files in C:\$WINDOWS.~BT

so I would like to delete the folder C:\$WINDOWS.~BT

I tried putting C:\$WINDOWS.~BT

into $aFileList with this code:

Global $aFileList[35]

If @error = 4 Then
        $aFileList[0] = 1
        $aFileList[1] = $FilePath
    EndIf

The above code doesn't seem to work.

Does anyone know what I am doing wrong?

Thanks,

 

Edited by Docfxit
Posted
Quote

doesn't seem to work.

Doesn't help much. Do you get any error messages?
Are you sure you can delete a directory using the -L parameter?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted (edited)

With this code:

Global $aFileList[35]

If @error = 4 Then
        MsgBox($MB_SYSTEMMODAL, "", "No file(s) were found.")
        $aFileList[0] = 1
        $aFileList[1] = $FilePath
        _ArrayDisplay($aFileList, "Files Found")
        ;Exit
    EndIf

I don't get any error message.

I do get the MsgBox to pop up.

I don't get the Array $aFileList to display.

Edited by Docfxit
Sorry. I didn't show the array defined
Posted (edited)
On 5/16/2020 at 9:46 PM, Docfxit said:
If @error = 4 Then
        $aFileList[0] = 1
        $aFileList[1] = $FilePath
    EndIf

The above code doesn't seem to work.

Does anyone know what I am doing wrong?

If you got @error = 4 from _FileListToArray, then $aFileList will not be a valid array.  Therefore,  you cannot assign values to it as if it was an array.

If you ran that code in Scite, you should have seen the following error "Subscript used on non-accessible variable"

Edited by TheXman
Posted

The array had been defined at the beginning of the original script.  At the time I got @error = 4 there was nothing in the array.  I tried putting something in the array after the error.

 

Posted (edited)

It doesn't matter whether it was a valid array before the function was executed.  After the function was executed, it was no longer a valid array.  Run the simple example below.

#include <Constants.au3>
#include <File.au3>

simple_example()

Func simple_example()
    Local $a[0] ;initialized to a valid empty array

    MsgBox($MB_ICONINFORMATION, "Before Function", "IsArray($a) = " & IsArray($a))

    $a = _FileListToArray ("C:\", "cmon.useyourbrain")
    If @error Then
        MsgBox( _
            $MB_ICONERROR, "ERROR", _
            "@error = " & @error & @CRLF & _
            "IsArray($a) = " & IsArray($a) & @CRLF & _
            "VarGetType($a) = " & VarGetType($a) & @CRLF & _
            "$a = " & $a)
        Exit 1
    EndIf
EndFunc

 

Edited by TheXman
Posted (edited)

If it's not a valid array at that point can I create a new array with the same name?

Global $aFileList[35]

    If @error = 4 Then
        MsgBox($MB_SYSTEMMODAL, "", "No file(s) were found.")
    Global $aFileList[0] ;initialized to a valid empty array
        $aFileList[0] = 1
        $aFileList[1] = $FilePath
        _ArrayDisplay($aFileList, "Files Found")
    EndIf

 

Edited by Docfxit
Posted (edited)
42 minutes ago, Docfxit said:

If it's not a valid array at that point can I create a new array with the same name?

Global $aFileList[35]

    If @error = 4 Then
        MsgBox($MB_SYSTEMMODAL, "", "No file(s) were found.")
    Local $aFileList[0] ;initialized to a valid empty array
        $aFileList[0] = 1
        $aFileList[1] = $FilePath
        _ArrayDisplay($aFileList, "Files Found")
    EndIf

 

You obviously didn't even take the time to test the code you just suggested.  Because if you had, then you would have seen that it generated an error.  It generates an error because you create an array with 0 slots and then try to put 2 items into slots that do not exist.  If you are too lazy to test your own code first, then you must be looking for someone to write it for you.  Sorry, but I only help those that are trying to learn and that put in the effort.  You can waste someone else's time.

Edited by TheXman
Posted (edited)
4 hours ago, Docfxit said:

If it's not a valid array at that point can I create a new array with the same name?

Here is a quick array test prog. It shows the difference between Global and Local+Global definition in the function.

 

#include <Array.au3>
Global $Ara[10]

For $x = 0 To 9
    $Ara[$x] = Random(0, 1000)
Next

_ArrayDisplay($Ara, "01 Array Contents:")
aDebug()
_ArrayDisplay($Ara, "03 Does Array contain aDebug changes ? no")
bDebug()
_ArrayDisplay($Ara, "05 Does Array contain bDebug changes ? Yes")

Func aDebug()
    Local $Ara[7]                   ;This creates a new array bound to the aDebug function, regardless of the maincode global definition
                                    ;It is created anew for every aDebug() function call, and is deleted at the exit from the function.
    For $x = 0 To 6
        $Ara[$x] = Chr(48+$x)
    Next
    _ArrayDisplay($Ara, "02 Array display inside the aDebug function")
EndFunc   ;==>aDebug


Func bDebug()
    Global $Ara[6]                  ;This redefines the array , and changes it Globally
    For $x = 0 To 5
        $Ara[$x] = Chr(64+$x)
    Next
    _ArrayDisplay($Ara, "04 Array display inside the bDebug function")
EndFunc   ;==>aDebug

 

Edited by Dan_555

Some of my script sourcecode

Posted
12 hours ago, TheXman said:

You obviously didn't even take the time to test the code you just suggested.  Because if you had, then you would have seen that it generated an error.  It generates an error because you create an array with 0 slots and then try to put 2 items into slots that do not exist.  If you are too lazy to test your own code first, then you must be looking for someone to write it for you.  Sorry, but I only help those that are trying to learn and that put in the effort.  You can waste someone else's time.

I did test it.  It didn't work. I didn't know how to get it to work.  I was hoping someone would make a suggestion on how to get it to work.

Thanks for your help.

Docfxit

Posted
8 hours ago, Dan_555 said:

Here is a quick array test prog. It shows the difference between Global and Local+Global definition in the function.

 

#include <Array.au3>
Global $Ara[10]

For $x = 0 To 9
    $Ara[$x] = Random(0, 1000)
Next

_ArrayDisplay($Ara, "01 Array Contents:")
aDebug()
_ArrayDisplay($Ara, "03 Does Array contain aDebug changes ? no")
bDebug()
_ArrayDisplay($Ara, "05 Does Array contain bDebug changes ? Yes")

Func aDebug()
    Local $Ara[7]                   ;This creates a new array bound to the aDebug function, regardless of the maincode global definition
                                    ;It is created anew for every aDebug() function call, and is deleted at the exit from the function.
    For $x = 0 To 6
        $Ara[$x] = Chr(48+$x)
    Next
    _ArrayDisplay($Ara, "02 Array display inside the aDebug function")
EndFunc   ;==>aDebug


Func bDebug()
    Global $Ara[6]                  ;This redefines the array , and changes it Globally
    For $x = 0 To 5
        $Ara[$x] = Chr(64+$x)
    Next
    _ArrayDisplay($Ara, "04 Array display inside the bDebug function")
EndFunc   ;==>aDebug

 

That's a great example.  Now I understand what I can do with it. 

Thank you very much.  I will apply that to my creation now.

Have a great day.

Docfxit

Posted

I did successfully add the array back in with your great example.

I had to run the script once to delete all the files in the folder and then when it was empty run the script a second time to delete the folder itself.

I took a different approach, After the file of all the files was created I added one record to the end of the file list with the folder name in it.

Now it deletes all files and the folder in one pass.

The completed code is post#3 of this thread.

Thank you all for your help,

Docfxit

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
×
×
  • Create New...