Thank you all for your advice. My reading of your answers is that two approaches would help:
- Reorganise into subdirectories as I originally thought
- Use while instead of foreach
I have already converted to using while
but I haven't had the chance to check for improvement yet. Can I have opinions on whether using both solutions together is worthwhile (pun not intended!)?
BTW, the file names are email addresses (opt-in list, no spam here I promise!!) with \W characters removed. I was planning to pick 2nd and 4th chars to name the subdirectories in order to avoid grubbiness. Any thoughts on that?