jkemp Posted January 30, 2018 Posted January 30, 2018 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")
iamtheky Posted January 30, 2018 Posted January 30, 2018 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. ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
Subz Posted January 30, 2018 Posted January 30, 2018 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) mikell and 232showtime 2
jkemp Posted January 31, 2018 Author Posted January 31, 2018 After making a couple of adjustments it work perfect. Thanks for the assist subz
jkemp Posted January 31, 2018 Author Posted January 31, 2018 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.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now