System.IO Process Subdirectories

This piece of code will iterate all the subdirectories in a folder. It will then process all the files in those subdirectories

    Public Sub Process()
 
        'loop through the folders
        Dim strDirectory As String = System.Configuration.ConfigurationManager.AppSettings("RootDirectory")
 
        Dim strFileNameOnly As String = ""
        Dim strFileNameAndPath As String = ""
        Dim strSubdirectoryName As String = ""
 
        Dim oDirectory As New DirectoryInfo(strDirectory)
        For Each oSubDirectories As DirectoryInfo In oDirectory.GetDirectories
            'get the folder name
            strSubdirectoryName = oSubDirectories.FullName
 
            'translate it
 
            'loop through the files in a folder
            Dim oSubdirectory As New DirectoryInfo(strSubdirectoryName)
            For Each oFile As FileInfo In oSubdirectory.GetFiles()
                strFileNameOnly = oFile.Name
                strFileNameAndPath = oFile.FullName
 
                If strFileNameOnly.ToUpper = "CHART.CSV" Then
                    'process COA files
                    ProcessCOAFile()
                Else
                    'process other files
                    ProcessGLFile()
                End If
 
 
            Next
        Next
 
    End Sub

RealWorldCode gives developers practical, real‑world solutions with clean, working code — no fluff, no theory, just answers.
Links
Home
Knowledge Areas
Sitemap
Contact
Et cetera
Privacy Policy
Terms and Conditions
Cookie Preferences