troubleshooting Question

VBA - Processing all files in a folder (there's a catch)

Avatar of BassetPatrol
BassetPatrolFlag for United States of America asked on
SoftwareVisual Basic ClassicVB Script
5 Comments1 Solution1111 ViewsLast Modified:
My Goal: batch process all files in two folders
               (I can do this when working with only one root folder)
My delima: I have a root folder named 'LAS_files' and another root folder named 'Roads_dgn'.
The process preformed is basically this:
-read LAS file into Microstation (This would be obtained from the 'LAS_files' folder)
-read in the matching file from the 'Roads_dgn' folder, based on name(This would be obtained from the 'Roads_dgn' folder)
-do some stuff(which includes unloading the current .LAS file)
-Repeat the process with the next .LAS file in the 'LAS_files' folder and the next dgn file in the 'Roads_dgn' folder until all are done

I'm trying to determine the best way to accomplish this.  
I've thought about having the user enter the path to the 'Roads_dgn' folder and then using string manipulation to extract the portion of the name I would need from the 'LAS_files' file name and handle it that way.  
However I thought that perhaps there was a way using the 'batch process' for all files in one folder to apply it to two folders, one being dependent on the other.

results of the below code will show up in the Immediate window of the Visual Basic editor
Private Sub cmdJustRunAlready_Click()
Dim myFSO As New Scripting.FileSystemObject
Dim myFolder As Scripting.folder
Dim myshell As New Shell32.Shell
Dim myRootFolder As Shell32.Folder3
'Set myRootFolder = myshell.browseforfolder(0, "Pick", 0)--Original from Microstation VBA book Pg606
Set myRootFolder = myshell.BrowseForFolder(0, "Browse to .LAS folder.", 0)
Set myFolder = myFSO.GetFolder(myRootFolder.Self.Path)
ProcessFilesAndSubs myFolder
End Sub
Sub ProcessFilesAndSubs(FolderIn As Scripting.folder)
Dim myFile As Scripting.File
Dim mySubFolder As Scripting.folder
For Each myFile In FolderIn.Files
    Select Case UCase(Right(myFile.Name, 3))
    Case "LAS"
    Debug.Print myFile.Path
   ' MsgBox ("This is where the action happens") 
    'would need to place code that needed to happen to each file here
    'At this point path name I'm working with is myFile.Path
    End Select
For Each mySubFolder In FolderIn.SubFolders
ProcessFilesAndSubs mySubFolder
End Sub
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 5 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros