Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Archivo TXT no se cierra
Message
From
21/10/2015 15:02:25
 
 
To
All
General information
Forum:
ASP.NET
Category:
Other
Title:
Archivo TXT no se cierra
Environment versions
Environment:
VB 9.0
OS:
Windows 8.1
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Desktop
Miscellaneous
Thread ID:
01626287
Message ID:
01626287
Views:
40
Saludos;

Tengo una función la cual hace un merge de archivos TXT; esta hace un recorrido por diferentes carpetas y a tomando los archivos txt que en cada carpeta se encuentra y luego va creando archivos pres donde va juntando la información de cada archivo.

El problema que tengo es que despues que la función hace el barrido por todas las carpetas, la función genera el siguiente eror:

An unhandled exception of type 'System.IO.IOException' occurred in mscorlib.dll

Additional information: The process cannot access the file 'C:\Users\liderapp\Documents\Scripts\Octubre2015\CM.TXT' because it is being used by another process.

La función de las que les hablo es:
        ' Itero cada directorio del directorio de origen.
        For Each topDir As DirectoryInfo In New DirectoryInfo(sourceDir).GetDirectories("*", SearchOption.TopDirectoryOnly)

            ' Itero de forma recursiva cada subdirectorio del directorio actual.
            For Each subDir As DirectoryInfo In topDir.GetDirectories("*", SearchOption.AllDirectories)

                ' Itero de forma recursiva cada archivo de texto del directorio actual.
                For Each txtfile As FileInfo In topDir.GetFiles("*.txt", SearchOption.AllDirectories)

                    If txtfile.Name.Equals(NameCM, StringComparison.OrdinalIgnoreCase) Then
                        curFilename = NameCM

                    ElseIf txtfile.Name.Equals(NameGL, StringComparison.OrdinalIgnoreCase) Then
                        curFilename = NameGL

                    ElseIf txtfile.Name.Equals(NameImp60, StringComparison.OrdinalIgnoreCase) Then
                        curFilename = NameImp60

                    ElseIf txtfile.Name.Equals(NameImp61, StringComparison.OrdinalIgnoreCase) Then
                        curFilename = NameImp61

                    ElseIf txtfile.Name.Equals(NameImp62, StringComparison.OrdinalIgnoreCase) Then
                        curFilename = NameImp62

                    ElseIf txtfile.Name.Equals(NameImp63, StringComparison.OrdinalIgnoreCase) Then
                        curFilename = NameImp63
                    Else
                        curFilename = String.Empty
                    End If
                    If Not String.IsNullOrEmpty(curFilename) Then
                        Debug.WriteLine(topDir.FullName)
                        Debug.WriteLine(subDir.FullName)
                        Debug.WriteLine(txtfile.FullName)
                        Debug.WriteLine(Path.Combine(topDir.FullName, curFilename))
                        Using sr As StreamReader = txtfile.OpenText
                            File.AppendAllText(Path.Combine(topDir.FullName, curFilename), sr.ReadToEnd, Encoding.Default)
                        End Using
                    End If
                Next txtfile
            Next subDir
        Next topDir
Y el error se dá exctamente en esta sentencia:

File.AppendAllText(Path.Combine(topDir.FullName, curFilename), sr.ReadToEnd, Encoding.Default)

Alguien podría orientarme de como resolver este error?

Muchisimas gracias por adelantado.
Reply
Map
View

Click here to load this message in the networking platform