Jump to content
jkemp

ArraySearch and ArrayDelete help

Recommended Posts

jkemp

I need to search an array and remove parts that will not be worked with.  I have tried using ArraySearch and ArrayDelete in combination.  In order to save some typing I have been trying to search the main word in the string of the element I am trying to delete from the array.  What I am trying to remove from the array is a filepath, if I do the ArraySearch for the entire filepath everything works fine.  Here is what I have so far.

    ; List all the User profiles containing TileDataLayer folder return the full path.
    Local $aFileList = _FileListToArray("C:\Users\","*", $FLTA_FOLDERS, True)
    If @error = 1 Then
        MsgBox($MB_SYSTEMMODAL, "", "Path was invalid.")
        Exit
    EndIf
    If @error = 4 Then
        MsgBox($MB_SYSTEMMODAL, "", "No file(s) were found.")
        Exit
    EndIf


    For $i = 1 to $aFileList[0] step 1
        $aFileList[$i] = $aFileList[$i] & "\AppData\Local\TileDataLayer"

    Next
    _ArrayDisplay ($aFileList, "$aFileList")

Local $iDel = _ArraySearch($aFileList,"\default\")
    _ArrayDelete($aFileList, $iDel)
    _ArrayDisplay ($aFileList, "REVISED FILE LIST")

Share this post


Link to post
Share on other sites
iamtheky

look at _ArrayFindAll

If you take the 1D array it returns and use _ArrayAdd to set element 0 to the number of elements, then you can pass that array to _ArrayDelete instead of needing to loop.


,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites
Subz

Maybe something like below will give you better results:

#include <Array.au3>
#include <File.au3>

Local $sError = ""
Local $aFileList = _FileListToArrayRec("C:\Users", "TileDataLayer||Default", $FLTAR_FOLDERS + $FLTAR_NOHIDDEN + $FLTAR_NOSYSTEM, $FLTAR_RECUR, $FLTAR_FASTSORT, $FLTAR_FULLPATH)
   Switch @error
        Case 1
           $sError = " - Path not found or invalid"
        Case 2
           $sError = " - Invalid Include parameter"
        Case 3
           $sError = " - Invalid Exclude parameter"
        Case 4
           $sError = " - Invalid Exclude_Folders parameter"
        Case 5
           $sError = " - Invalid $iReturn parameter"
        Case 6
           $sError = " - Invalid $iRecur parameter"
        Case 7
           $sError = " - Invalid $iSort parameter"
        Case 8
           $sError = " - Invalid $iReturnPath parameter"
        Case 9
           $sError = " - No files/folders found"
   EndSwitch
   If $sError <> "" Then MsgBox(32, "Error", $sError)

_ArrayDisplay($aFileList)

 

  • Like 2

Share this post


Link to post
Share on other sites
jkemp

After making a couple of adjustments it work perfect.  Thanks for the assist subz

Share this post


Link to post
Share on other sites
jkemp
19 hours ago, Subz said:

Maybe something like below will give you better results:

#include <Array.au3>
#include <File.au3>

Local $sError = ""
Local $aFileList = _FileListToArrayRec("C:\Users", "TileDataLayer||Default", $FLTAR_FOLDERS + $FLTAR_NOHIDDEN + $FLTAR_NOSYSTEM, $FLTAR_RECUR, $FLTAR_FASTSORT, $FLTAR_FULLPATH)
   Switch @error
        Case 1
           $sError = " - Path not found or invalid"
        Case 2
           $sError = " - Invalid Include parameter"
        Case 3
           $sError = " - Invalid Exclude parameter"
        Case 4
           $sError = " - Invalid Exclude_Folders parameter"
        Case 5
           $sError = " - Invalid $iReturn parameter"
        Case 6
           $sError = " - Invalid $iRecur parameter"
        Case 7
           $sError = " - Invalid $iSort parameter"
        Case 8
           $sError = " - Invalid $iReturnPath parameter"
        Case 9
           $sError = " - No files/folders found"
   EndSwitch
   If $sError <> "" Then MsgBox(32, "Error", $sError)

_ArrayDisplay($aFileList)

 

Moved "default" into the exclude filter of the $smask and removed the nohidden attribute and it returned an array exactly like I wanted.

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

×