kcvinu Posted March 8, 2015 Share Posted March 8, 2015 Hi all, I am trying to delete a specific element from a 1D array. But it doesn't delete the specific item. Here is my code Local $Items_InFolder Local $element Local $Search_String Local $Comparison $Items_InFolder= _FileListToArray(@ScriptDir) $Search_String = "- AutoIt Forums_files" For $element In $Items_InFolder $Comparison = StringInStr($element,$Search_String) If $Comparison < 1 Then _ArrayDelete($Items_InFolder,$element) EndIf Next Spoiler My Contributions Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language. UDF Link Viewer --- A tool to visit the links of some most important UDFs Includer_2 ----- A tool to type the #include statement automatically Digits To Date ----- date from 3 integer values PrintList ----- prints arrays into console for testing. Alert ------ An alternative for MsgBox MousePosition ------- A simple tooltip display of mouse position GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function Access_UDF -------- An UDF for working with access database files. (.*accdb only) Link to comment Share on other sites More sharing options...
JohnOne Posted March 8, 2015 Share Posted March 8, 2015 (edited) Need to go backwards when deleting array elements. #include <File.au3> #include <Array.au3> Local $Items_InFolder Local $element Local $Search_String Local $Comparison $Items_InFolder= _FileListToArray(@ScriptDir) _ArrayDisplay($Items_InFolder) $Search_String = "- AutoIt Forums_files" For $element = $Items_InFolder[0] To 1 Step -1 $Comparison = StringInStr($Items_InFolder[$element],$Search_String); EDIT: oops StringInStr($element,$Search_String) If $Comparison < 1 Then _ArrayDelete($Items_InFolder,$element) $Items_InFolder[0] -= 1 EndIf Next _ArrayDisplay($Items_InFolder) Edited March 8, 2015 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
JohnOne Posted March 8, 2015 Share Posted March 8, 2015 Edited, sorry for mistake. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
mikell Posted March 8, 2015 Share Posted March 8, 2015 BTW you should avoid the use of For/in/Next loops (_Array* funcs mainly work using indexes ) Example #include <Array.au3> Local $aArray[5] = ["test0", "test2", "test4", "test6", "test8"] ;_ArrayDisplay($aArray, "Original") For $vElement In $aArray If StringInStr($vElement, "6") Then Msgbox(0,"", $vElement) _ArrayDelete($aArray, $vElement) ; <== doesnt work EndIf Next _ArrayDisplay($aArray, "Element deleted") kcvinu 1 Link to comment Share on other sites More sharing options...
kcvinu Posted March 8, 2015 Author Share Posted March 8, 2015 (edited) @ JohnOne I think ArrayName[0] is the first element of the array. Then how can you iterate from start to end with a minus step value ? Edit: You are iterating from 0th element to 1st element ?. Edited March 8, 2015 by kcvinu Spoiler My Contributions Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language. UDF Link Viewer --- A tool to visit the links of some most important UDFs Includer_2 ----- A tool to type the #include statement automatically Digits To Date ----- date from 3 integer values PrintList ----- prints arrays into console for testing. Alert ------ An alternative for MsgBox MousePosition ------- A simple tooltip display of mouse position GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function Access_UDF -------- An UDF for working with access database files. (.*accdb only) Link to comment Share on other sites More sharing options...
Solution JohnOne Posted March 8, 2015 Solution Share Posted March 8, 2015 (edited) $aArray[0] = Number of FilesFolders returnedhttps://www.autoitscript.com/autoit3/docs/libfunctions/_FileListToArray.htm Edited March 8, 2015 by JohnOne kcvinu 1 AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
kcvinu Posted March 8, 2015 Author Share Posted March 8, 2015 Ok...Ok.. Now i got it. Spoiler My Contributions Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language. UDF Link Viewer --- A tool to visit the links of some most important UDFs Includer_2 ----- A tool to type the #include statement automatically Digits To Date ----- date from 3 integer values PrintList ----- prints arrays into console for testing. Alert ------ An alternative for MsgBox MousePosition ------- A simple tooltip display of mouse position GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function Access_UDF -------- An UDF for working with access database files. (.*accdb only) Link to comment Share on other sites More sharing options...
kcvinu Posted March 8, 2015 Author Share Posted March 8, 2015 Thank you JohnOne, Solved. I wanted to delete a file named "lightbox.JS" But there are plenty of them. So i made a script to delete it. And it will do the job in 1 second. There are 49 files in 49 folders. Thanks to autoit. Spoiler My Contributions Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language. UDF Link Viewer --- A tool to visit the links of some most important UDFs Includer_2 ----- A tool to type the #include statement automatically Digits To Date ----- date from 3 integer values PrintList ----- prints arrays into console for testing. Alert ------ An alternative for MsgBox MousePosition ------- A simple tooltip display of mouse position GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function Access_UDF -------- An UDF for working with access database files. (.*accdb only) Link to comment Share on other sites More sharing options...
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