I need to open all files that are contained in a chosen folder. I want to open and revise a file one a time. I will be selecting the folder thru the use of a DirList Box. How would one go about this?
I need to open all files that are contained in a chosen folder. I want to open and revise a file one a time. I will be selecting the folder thru the use of a DirList Box. How would one go about this?
Best regardsVB Code:
Public Sub ReviseFolder(ByVal sPath As String) Dim sFile As String If Right$(sPath, 1) <> "\" Then sPath = sPath & "\" End If sFile = Dir(sPath & "*.*") Do While Len(sFile) 'check to see so the file isn't a subfolder. If (GetAttr(sPath & sFile) And vbDirectory) <> vbDirectory Then 'Code to open the file and do the revise goes here End If sFile = Dir Loop End Sub
OK....
We're close but not quite there yet.
Now I am at least opening a file with the name of each that is in the folder but the problem now is that the DIR function is losing the path of each file. It is only giving me the filenames themselves.
Maybe DIR isn't the way to go here? Any ideas?
Maybe something like this.VB Code:
Private Sub Command1_Click() Dim strPath As String Dim strFile As String Dim strTemp As String strPath = "c:\testFolder\" 'Set strFile to the first file in the folder strFile = Dir(strPath & "*") 'Loop until strFile is empty, indicating that there are no more files Do Until strFile = "" Open strPath & strFile For Input As #1 Do While Not EOF(1) Line Input #1, strTemp Debug.Print strTemp Loop Close #1 'Set strFile to the next file in the folder strFile = Dir Loop End Sub
Hey Thanks tons guys! Both them work. When I passed the sFile as a parameter along with sPath into my sub, it worked like a charm.
So, in short, my algorithm was missing a vital piece of info and was just doing what I told it to.
Again thanks much both of you!