Actually, trcloke, not that it's all that difficult, but in most operating systems, you don't need to generate your own list of the files in a directory. Doing something to all the files in a directory is an operation that is often needed, and most operating systems provide commands to do exactly that. Specifically, read through the following links. Since you haven't told us what OS you are using, I used an example from DOS, but similar commands exist in all the variants of UNIX that I know, and probably exist in Macs, but I'm not familiar with that OS.
How to do something to each file in a directory with a batch script , and,
Loop Through All Files In A Directory With DOS Batch
These links should show you that you can do exactly what I said, using the "for" command in a batch file. It only will take a few lines of code, will be vastly more efficient and use less memory than opening and manipulating images within PS, and is a very worthwhile skill to develop.
HTH,
Tom
PS - Although you don't need it for this project, should you ever need a list of all the files in a directory put in a text file, just search on {dos redirection} and/or {dos pipes}. It's incredibly simple: at the command prompt, you just type something like: dir *.* > list.txt, and you have what you want.