Jump to content

StringRegExp in an array not working


kor
 Share

Go to solution Solved by kor,

Recommended Posts

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
Link to comment
Share on other sites

  • Developers

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

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Solution

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)
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...