I currently have a task in which I run a terminal command to write the name and path of the files in that folder and its sub-folders into a text file. That command outputs that text file incredibly fast (a matter of maybe 5 - 10 seconds for 7500 files). I then populate a global variable with the number of files listed in that text file.
A1: Anchor
A2: Flash [ Text:Building new file list... Long:Off ]
A3: Run Shell [ Command:find /mnt/extSdCard/files/. -type f -name *.db -exec rm {} \; Timeout (Seconds):0 Use Root:On Store Output In: Store Errors In: Store Result In: Continue Task After Error:On ]
A4: Run Shell [ Command:find /mnt/extSdCard/files/ -type f > /mnt/extSdCard/files/List.txt Timeout (Seconds):0 Use Root:On Store Output In: Store Errors In: Store Result In: Continue Task After Error:On ]
A5: Run Shell [ Command:find /mnt/extSdCard/files -not -type d | wc -l Timeout (Seconds):0 Use Root:On Store Output In:%NumberOfDFs Store Errors In: Store Result In: Continue Task After Error:On ]
A6: Flash [ Text:New Default file list built! Files found: %NumberOfDFs Long:Off ]
A3 - deletes any Windows thumbnail .db files that got copied into the SDCard (when the phone was attached to the PC to transfer pictures files, for example)
A4 - this shell command creates the text file that contains the complete file listing, including path to each file, and it's individual extension (so in my case, I could have .PNG and/or .JPG and/or .BMP files for wallpaper, without worrying about what type of file it is, what it's called, and where it is located (which also allows me to have a heirarchy of files, sorted to the way I like ;) ))
A5 - this shell command gives you the total number of files in the entire folder heirarchy you have setup, and counts only files, and not the number of folders. This is useful for those of you, like me, who use a 'Variable Randomize' action to pick an individual line number from a group of numbers between 1 and the total number of files to randomize which file, for example, is used to set your wallpaper.
I don't think you need Root, but I have it on my phone, so put a check mark in the option to use it.
Those 2 commands create a file with the listing contained within, AND the total number of files in any specified folder, within SECONDS. I use these 2 commands to list and count over 7500 files in... get this... 10 seconds. Tasker, using 'For' loops and whatnot, can take over 25 MINUTES to do the same. This isn't a knock on Tasker at all (so Pent, don't be upset with me for saying that ;) ), but instead is a compliment to the number of things that Tasker allows you to do.
I hope someone else finds this as useful as I did when I figured out how to do it. :)