Results 1 to 5 of 5

Thread: Opening,revising, & closing, sequentially, all files with in a folder

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2001
    Posts
    37

    Cool 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?

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    VB Code:
    1. Public Sub ReviseFolder(ByVal sPath As String)
    2.     Dim sFile As String
    3.     If Right$(sPath, 1) <> "\" Then
    4.         sPath = sPath & "\"
    5.     End If
    6.     sFile = Dir(sPath & "*.*")
    7.     Do While Len(sFile)
    8.         'check to see so the file isn't a subfolder.
    9.         If (GetAttr(sPath & sFile) And vbDirectory) <> vbDirectory Then
    10.             'Code to open the file and do the revise goes here
    11.         End If
    12.         sFile = Dir
    13.     Loop
    14. End Sub
    Best regards

  3. #3

    Thread Starter
    Member
    Join Date
    Aug 2001
    Posts
    37
    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?

  4. #4
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    736
    Maybe something like this.
    VB Code:
    1. Private Sub Command1_Click()
    2.     Dim strPath As String
    3.     Dim strFile As String
    4.     Dim strTemp As String
    5.    
    6.     strPath = "c:\testFolder\"
    7.     'Set strFile to the first file in the folder
    8.     strFile = Dir(strPath & "*")
    9.    
    10.     'Loop until strFile is empty, indicating that there are no more files
    11.     Do Until strFile = ""
    12.         Open strPath & strFile For Input As #1
    13.         Do While Not EOF(1)
    14.             Line Input #1, strTemp
    15.             Debug.Print strTemp
    16.         Loop
    17.         Close #1
    18.         'Set strFile to the next file in the folder
    19.         strFile = Dir
    20.     Loop
    21. End Sub

  5. #5

    Thread Starter
    Member
    Join Date
    Aug 2001
    Posts
    37
    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
  •  



Click Here to Expand Forum to Full Width