i/o process multiple text files

I want to write a program to do some simple search & replace type stuff on text files located within a single directory.
Assuming that the NUMBER of files to process will vary, and the NAMES of these files will vary, what would be the best way to get the actual "program loop" to automatically select and start processing, and when it completes and closes the first file, move on to the second, third, etc. until all files have been done?
I don't need help on the actual Search & Replace, I guess I'd like to see a code example of how the program could read the names of the files in "directory x" and then loop through all files until it has performed the S&R (or any other) function on every file it finds in "directory x".  

Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

moterkConnect With a Mentor Commented:
'TxtPath folder with text files

if right(TxtPath,1)<>"\" then TxtPath=TxtPath+"\"

TxtFile$=Dir(TxtPath & "*.txt")
do until TxtFile$=""
    ' add open, read, process, and
    ' close stuff here
Dim FileToOpen As String
Dim MyDir as String
Dim FileNo
MyDir = "Path & Dir Name\"
FileToOpen = Dir(MyDir & "*", vbNormal)
While FileToOpen <> ""
  FileNo = FreeFile
  Open MyDir & FileToOpen for Input as #FileNo

   'Your code here

  Close #FileNo
  FileToOpen = Dir
Don't forget to put a DoEvents statement in the loop and a Cancel option.
nascar_3Author Commented:
Both Hes & Moterk's Answers are very similar.
I did try Hes' code FIRST, but for some (unexplored) reason, I could not get it running right away, and after several failed attempts to fix it, I switched to Moterk's code and got it running immediately.
Moterk's was also shorter and to-the-point, so....
points given to Moterk!

All Courses

From novice to tech pro — start learning today.