Sign in to follow this  
Followers 0
kor

StringRegExp in an array not working

4 posts in this topic

#1 ·  Posted (edited)

I seriously don't understand this. I thought I had arrays and loops down pretty well.

Error:
adtechscriptsAvigilon.au3 (14) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
If StringRegExp($aFolders[$i], "w") Then _ArrayDelete($aFolders, $i)
If StringRegExp(^ ERROR
 
All I'm trying to do is loop through a folder list and if any folder contains the $ character delete that line from the array.
 
#include <Array.au3>
#include <File.au3>
 
Global $sAvigilonPath = "\\ad\data\avigilon"
 
$aFolders = _FileListToArray($sAvigilonPath, "*", 2)
If @error Then ConsoleWrite("! - ERROR - Error reading folder list")
 
_ArrayDisplay($aFolders)
 
For $i = 0 To UBound($aFolders) - 1
;ConsoleWrite($aFolders[$i] & @CR)
If StringRegExp($aFolders[$i], "$") Then _ArrayDelete($aFolders, $i)
Next
 
_ArrayDisplay($aFolders)
Edited by kor

Share this post


Link to post
Share on other sites



You are deleting entries in your array so you need to go from high to low to avoid this issue.

Jos

 

This doesn't seem to work either

For $i = UBound($aFolders) - 1 To 0 Step - 1

Share this post


Link to post
Share on other sites

Got it.

Working code

#include <Array.au3>
#include <File.au3>
 
Global $sAvigilonPath = "\\ad\data\avigilon"
 
$aFolders = _FileListToArray($sAvigilonPath, "*", 2)
If @error Then ConsoleWrite("! - ERROR - Error reading folder list")
 
_ArrayDisplay($aFolders)
 
For $i = UBound($aFolders) - 1 To 0 Step - 1
If Not StringRegExp($aFolders[$i], "\A[^\W]") Then _ArrayDelete($aFolders, $i)
Next
 
_ArrayDisplay($aFolders)

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