Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
TXT file doesn´t close
Message
From
23/10/2015 09:05:05
 
 
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
VB.NET 1.1
OS:
Windows 8.1
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Desktop
Miscellaneous
Thread ID:
01626227
Message ID:
01626368
Views:
42
Hello every one;

I resolved the issue; I shared the function:
    Public Sub FindAndMergeFiles(ByVal sourceDir As String)
        Dim fileNames As String() =
        {
            "CM.txt", "GL.txt",
            "IMP6000.txt", "IMP6001.txt", "IMP6002.txt", "IMP6003.txt"
        }

        Dim curFilename As String = String.Empty
        For Each topDir As DirectoryInfo In New DirectoryInfo(sourceDir).GetDirectories("*", SearchOption.TopDirectoryOnly)
            ' Elimino los archivos principales ("...\topDir\CM.txt", "...\topDir\GL.txt", etc...) de sesiones anteriores.
            For Each txtfile As FileInfo In topDir.GetFiles("*.txt", SearchOption.TopDirectoryOnly)
                If fileNames.Contains(txtfile.Name, StringComparer.OrdinalIgnoreCase) Then
                    txtfile.Delete()
                End If
            Next txtfile
            For Each subDir As DirectoryInfo In topDir.GetDirectories("*", SearchOption.AllDirectories)
                For Each txtfile As FileInfo In subDir.GetFiles("*.txt", SearchOption.AllDirectories)
                    If fileNames.Contains(txtfile.Name, StringComparer.OrdinalIgnoreCase) Then
                        curFilename = fileNames.First(Function(filename) filename.Equals(txtfile.Name, StringComparison.OrdinalIgnoreCase))
                        Using sr As StreamReader = txtfile.OpenText
                            Using sw As New StreamWriter(Path.Combine(topDir.FullName, curFilename), append:=True, encoding:=Encoding.Default, bufferSize:=128)
                                sw.WriteLine(sr.ReadToEnd)
                            End Using ' sw
                        End Using ' sr
                    End If
                Next txtfile
            Next subDir
        Next topDir
    End Sub
Best regards;
Previous
Reply
Map
View

Click here to load this message in the networking platform