|
-
Aug 31st, 2001, 07:35 AM
#1
Thread Starter
Member
Opening,revising, & closing, sequentially, all files with in a folder
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?
-
Aug 31st, 2001, 08:00 AM
#2
VB 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
Best regards
-
Aug 31st, 2001, 10:19 AM
#3
Thread Starter
Member
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?
-
Aug 31st, 2001, 10:27 AM
#4
Fanatic Member
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
-
Aug 31st, 2001, 10:41 AM
#5
Thread Starter
Member
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!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|